Get data from HTTP response without ‘Parse JSON’ in Power Automate
Posted On February 7, 2021
“‘Parse JSON’ gives me a lot of useless dynamic contents, is there another way to parse the response from an HTTP request in Power Automate?”
When using HTTP requests in Power Automate, it’s recommended to use the ‘Parse JSON’ action to process the response. You take the HTTP response, use it as a sample payload in the ‘Parse JSON’, and the action will parse it for you. But if you do that, it’ll give you much more dynamic contents than you’d expect. It’ll parse everything in the HTTP response and add a ton of dynamic content, sometimes even doubling it. So, is there an easier way to get the data you need without using ‘Parse JSON’?
Access the data using expressions
When you look at the response from the HTTP request, you can see it’s a valid JSON. Let’s take an example, a response from an HTTP call that will return list of users in a SharePoint group.
The body of the example response will look as above. There’s the main element “d” (1), subelement “results” (2) with an array of users, and the actual user data (3). You can recognize that “results” is an array by the square brackets [ ] enclosing the user information (3). Since you’re interested in the user data, you want to loop through all the “results” and get the desired value for each user.
Expression to access the array
The first step is to get only the “results’ array from the object, and then use it in an ‘Apply to each’ action to process all items (users). Start from the default ‘body’ output from the HTTP action, it’ll look like: outputs(‘HTTP request action name’)?[‘body’], e.g. as below.
That’s the expression to use as the input of the ‘Apply to each’ action that will loop through all the results.
Expression to access the value
Now it’s time to select the value you want to get from that array. When processing an array inside ‘Apply to each’, you can access the currently processed item with item() expression. To continue with the example from above, each item() will contain only the part 3.
You’ll define what value from the item() you want by adding its key to the item() expression in the format below:
e.g. to get user Email address
And that’s the expression you can use to access the desired value from an HTTP request response, in this example the user email.
I’d say that’s the key takeaway from this article is to think about any input of ‘Parse JSON’ as an object. If it needs parsing, it’s an object and you can do all the object operations with it.
‘Parse JSON’ will just parse it for you and make the use more convenient, but it’s not the only way. You can skip that action and do the parsing by yourself, take only the values you really need and leave the rest.
Also, the HTTP request in this article was taken just as an example. You can follow the same process with minor variations for any HTTP request and its outcome. It’s just another object after all.