Json To Array Power Automate
Converting JSON to an array in Power Automate is a common task for anyone building flows that integrate with APIs, SharePoint, Microsoft Graph, or other services that return JSON payloads. Whether you need to iterate over items, filter data, or transform objects into a shape a downstream action expects, understanding how to turn JSON into a workable array is essential. Power Automate offers several built-in actions and expressions like Parse JSON, Select, Compose, and the json() function to help you convert, normalize, and manipulate JSON. This topic walks through practical methods, common pitfalls, and helpful tips so you can confidently convert JSON to arrays in your flows.
Why convert JSON to an array in Power Automate?
Many connectors return complex JSON objects. To loop over items, create batches, or map properties to another service, you usually need an array structure. Arrays are the native iterable type in Power Automate you can feed them into Apply to each, Select, Filter array, Create CSV table, and Compose actions. Converting JSON to an array unlocks these capabilities and makes data transformation reliable and repeatable.
Common methods to convert JSON to an array
1. Parse JSON action
The Parse JSON action is the most explicit and robust way to handle incoming JSON. It validates the structure and exposes properties for later actions in your flow.
- Use the HTTP, SharePoint or other connector to get a JSON response.
- Add a Parse JSON action and set the Content to the body of the response.
- Generate a schema automatically by pasting a representative JSON sample, or create a schema manually.
- After parsing, you can directly use dynamic content for array properties in Apply to each.
Pros type-safe, exposes fields as dynamic content. Cons requires a sample JSON or manual schema; strict validation can fail if response structure varies.
2. json() expression and Compose
If you have a JSON string and want to explicitly convert it into a JSON object or array, use the json() expression inside a Compose or Set variable action.
- Example
json(body('HTTP'))to convert an HTTP response string to a JSON object. - For string fields that contain JSON arrays, use
json(triggerOutputs()?['body']?['data']).
This is quick and flexible when you don’t want to enforce a schema, but you won’t get validated dynamic properties like with Parse JSON.
3. Select action to normalize objects into arrays
The Select action maps an input array of objects into a new array with a defined shape. It’s ideal when the JSON is already an array but needs reshaping.
- Input an array like
[{id"1,"name""A"},{"id"2,"name""B"}]. - In Select, map fields to new names
item()?['id']anditem()?['name']. - Output a normalized array ready for downstream consumption.
Select is powerful for mapping values and dropping unnecessary fields without code.
Typical workflows and examples
Example 1 API returns an object with an array property
Imagine an API returning{"status""ok","items"[{...},{...}]}. Steps
- Use HTTP action to call API.
- Parse JSON with body(‘HTTP’) and generate schema or include an items array in schema.
- Use Apply to each with the dynamic content items from Parse JSON (items). Inside the loop, process each item.
Example 2 API returns a JSON string inside a property
Some responses embed JSON as a string{"payload""[{\"id\"1},{\"id\"2}]"}. Steps
- Use Compose with
json(body('HTTP')?['payload'])to convert string to array. - Then use Apply to each over the Compose output.
Example 3 Convert comma-separated or custom text into array
Use split() when input is a delimitted stringsplit(body('Get_text'),',')returns an array. Use Select if you need objects rather than strings.
Power Automate expressions you’ll use often
json()converts a JSON string to an object/array.body('ActionName')returns action output (often JSON).items('Apply_to_each')returns the current item inside a loop.first(),last()extract elements from arrays.length()returns number of elements in an array.split()splits a string into an array.
Common pitfalls and how to fix them
1. Parse JSON fails due to changing schema
If the API sometimes omits fields, Parse JSON can fail. Mitigation
- Use a more flexible schema mark properties as optional or use types like “object” or “array” broadly.
- Use try/catch patterns with Configure run after and fallback Compose/json() parsing.
2. Array vs object confusion
Flows expect a true array for Apply to each. If you pass a JSON object, it will iterate over object properties (unexpected). Ensure you convert to an array withjson()or wrap single items in an arraycreateArray(body('Parse_JSON')).
3. Null or empty values
Null inputs break expressions. Use conditional checks likeif(equals(body('X'), null), createArray(), body('X'))or coalesce() to provide defaults.
Tips and best practices
- Prefer Parse JSON when you can provide a representative schema this makes later steps clearer and reduces expression complexity.
- Use Select to return only the fields you need and to rename properties for downstream connectors.
- Store intermediate JSON in Compose actions for debugging and readability Compose outputs are easy to inspect in flow runs.
- Use Initialize variable (Array) and Append to array variable if you need to accumulate values conditionally.
- Test with real API samples and edge cases (empty arrays, single items, null fields).
Debugging and monitoring
Use the flow run history to inspect raw JSON payloads. Check the outputs of HTTP, Parse JSON, and Compose steps to ensure the structure matches expectations. If an action fails, expand the failed step to see the exact error message Power Automate is usually specific about missing properties or type mismatches.
Converting JSON to an array in Power Automate is a foundational skill that unlocks many automation scenarios. Whether you use Parse JSON for strong typing, json() and Compose for flexibility, Select for mapping, or array variables for accumulation, the right approach depends on your input data and the reliability of the source. By mastering these actions and expressions and by testing with real-world samples you’ll be able to build robust flows that transform and iterate over JSON data with confidence.