cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
michaelshparber
Helper III
Helper III

Append JSON body responses without parsing

I am making a series of API calls via Do..until action.

Each call returns a body response in this form:

[
   {
   "id": "123",
   "status": "CLOSED"
   },
   {
   "id": "456",
   "status": "ACTIVE"
   }
]

 

Ho do I append all the responses without using Parse JSON?

I just want to save the appended results as a .json file in Sharepoint.

The problem is that it's appending the square brackets [] from each response together like this (see problem in red):

[
{
"id": "123",
"status": "CLOSED"
},
{
"id": "456",
"status": "ACTIVE"
}
]
[
{
"id": "999",
"status": "CLOSED"
},
{
"id": "888",
"status": "ACTIVE"
}
]

 

I would like to get this instead (please see comma instead of brackets between the call results:

 

[
{
"id": "123",
"status": "CLOSED"
},
{
"id": "456",
"status": "ACTIVE"
},
{
"id": "999",
"status": "CLOSED"
},
{
"id": "888",
"status": "ACTIVE"
}
]

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User III
Super User III

Actually there is a much easier way. Just union the results together.

 

  1. Make an array variable.
  2. Do all of your API calls.
  3. Create a compose which uses a union expression to join all of your results into one array.
  4. Assign the output of the compose to your array variable if you need to (but might not be required).

Much better solution.

View solution in original post

5 REPLIES 5
Paulie78
Super User III
Super User III

The calls are returning an array, which is correct from the point of view of an API call that can potentially return more than one result. So I would do this:

 

  1. Create an array variable of your own.
  2. Do your API call.
  3. Append the output to your new variable using the expression first(API_Call_Result). This will get the first (and only hopefully) record from within the returned results, and give you an array of results. 

Does that make sense?

Each of my responses returns an array of many results.

In my sample above there are two results - for each call. So I need total of four results.

So first() is not enough.

In real world I have hundreds of results in each call. So I thought of appending it just as variables - but the brackets get in the way...

Paulie78
Super User III
Super User III

Actually there is a much easier way. Just union the results together.

 

  1. Make an array variable.
  2. Do all of your API calls.
  3. Create a compose which uses a union expression to join all of your results into one array.
  4. Assign the output of the compose to your array variable if you need to (but might not be required).

Much better solution.

View solution in original post

Union! Awesome! 

I just need to have to somehow to save this array as a .json file.

How do I do it without Parsing?

In File Content - it allows me only to chose string variables, but now I have an array variable...

Please help @Paulie78 

Paulie78
Super User III
Super User III

Just convert it to a string with an expression like this:

string(variables('testArray'))

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Users online (10,617)