logo
search
Others

How to Combine Two Arrays into a JSON Object in Power Automate

Maira MehtabMaira Mehtab Oct 12, 2026 869 views

Question details

The user needs to map two separate arrays of the same length (a headers array and a values array) into a single, unified JSON object.

How to Combine Two Arrays into a JSON Object in Power Automate
Product
Power Automate
Device & OS
not provided
Scenario
Transforming paired array data into a structured key-value JSON object for subsequent data parsing and workflow automation.
Observed behavior
The data currently exists as two parallel arrays, preventing direct property access until they are dynamically combined into a standardized JSON format.
Before you start

Verify that both your headers array and values array have the exact same length to prevent out-of-bounds indexing errors during the flow execution.

Solution 1Recommended

Use a Select Action to Map Indexes

This is the recommended native approach for combining two arrays efficiently without using excessive loops.

By utilizing the Select action alongside the range() expression, Power Automate can iterate through an index array. This allows the flow to pluck the corresponding header and value at each index simultaneously to build the new JSON object.

1
Generate an Index Array

In your Select action, set the 'From' field to an expression that generates an array of numbers based on the length of your headers array, such as: range(0, length(variables('Headers'))).

2
Map Keys and Values

In the Map section of the Select action, switch to text mode. Use an expression to dynamically assign keys and values using the current item (index): { "@{variables('Headers')[item()]}": "@{variables('Values')[item()]}" }.

3
Parse the Generated Output

Add a 'Parse JSON' action immediately after your Select action. Pass the output of the Select action as the content and generate a schema based on your expected result to utilize typed properties later in your flow.

Use a Select Action to Map Indexes
Nested Loops Warning: For very large datasets, using a Select action is significantly faster than using an 'Apply to each' loop because it avoids sequential nesting bottlenecks.
Free Microsoft Office alternative

Need a Lightweight Alternative for Processing Exported Flow Data?

After using Power Automate to format your JSON arrays, you often need to export that data into CSVs or spreadsheets for analysis. WPS Office is a free, powerful alternative to Microsoft Office that perfectly handles data sheets generated from automated workflows.

  1. 1. Export Your Flow Data: In Power Automate, use the 'Create CSV table' action on your JSON object array and save it to your local storage.
  2. 2. Open WPS Spreadsheet: Launch the free WPS Office suite and open your newly exported CSV or Excel file.
  3. 3. Analyze Results: Use WPS Spreadsheet's built-in formulas and formatting tools to easily review your combined array data.
Completely free and lightweight Office suiteFully compatible with Microsoft Excel (.xlsx) and CSV formatsBuilt-in advanced tools for data analysis and formattingFamiliar user interface requiring zero learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Can I combine more than two arrays using the Select action?

Yes, provided all arrays share the exact same length. Since the Select action iterates over a numerical index array, you can map values from a third or fourth array in the same mapping step by referencing their respective variable indexes.

What happens if my headers array is longer than my values array?

If the arrays are of uneven lengths, the flow will result in an out-of-bounds error when the loop attempts to access an index that exists in the headers array but does not exist in the values array. Always validate array lengths prior to combining.

Why does my Parse JSON action fail after the Select step?

This generally occurs if the dynamically generated JSON structure does not match the schema you defined in the Parse JSON action. Run the flow once to get a successful output, copy the raw JSON, and use the 'Generate from sample' button to create a perfectly matched schema.