cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Convert JSON string to JSON array

I've got a system that handles some user input and for questions with multiple checkboxes, it stores the value as a string with a pipe delimiter. We need to transfer some of this data from this one system to a secondary system. Structure of the first system is fixed and can't be changed so I'm trying to use Flow to handle some of the data conversion in the middle
 
Here's how the data would be POSTed to Flow in key:value pair.
 
"components": "Value A | Value B | Value C"
 
Using Flow, I've been able to use the split() function to take this value and convert it to the following:
 
[
    "Value A",
    "Value B",
    "Value C"
]
 
This is where I get stuck. I need the array to be arranged as a JSON key:value pairing. It would need to look like this before I can transfer the JSON to a secondary system. How do I get the above string or array to output like below?
 
[
            {
                "name": "Value A"
            },
            {
                "name": "Value B"
            },
            {
                "name": "Value C"
            }
        ],
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Regular Visitor

Re: Convert JSON string to JSON array

Was able to fix my own issue using a combination of "Apply to Each" and the item() expression. I was able to output the value as follows:

[{"name":"Value A"},{"name":"Value B"},{"name":"Value C"}]

 

Step 1: Take the string, use split() to convert the string into an array based on the delimiter.

Step 2: Create an array variable with no value.

Step 3: Using the "Apply to each" control, take the Compose output from Step 1 and input the key pairing I needed, "name" in this case. The item() function returns an array object for each iteration when used with "Apply to each". 

Step 3A. Append the output from Compose 2 to the Array Variable. 

 

Here's a screenshot of the flow:

2018-12-05_17-31-13.jpg

View solution in original post

4 REPLIES 4
Highlighted
Regular Visitor

Re: Convert JSON string to JSON array

Was able to fix my own issue using a combination of "Apply to Each" and the item() expression. I was able to output the value as follows:

[{"name":"Value A"},{"name":"Value B"},{"name":"Value C"}]

 

Step 1: Take the string, use split() to convert the string into an array based on the delimiter.

Step 2: Create an array variable with no value.

Step 3: Using the "Apply to each" control, take the Compose output from Step 1 and input the key pairing I needed, "name" in this case. The item() function returns an array object for each iteration when used with "Apply to each". 

Step 3A. Append the output from Compose 2 to the Array Variable. 

 

Here's a screenshot of the flow:

2018-12-05_17-31-13.jpg

View solution in original post

Highlighted
Advocate II
Advocate II

Re: Convert JSON string to JSON array

Too long...

 

1, Init array variable

2, do ParseJSON for your JSON in string

3, Set body from ParseJSON outcome directly as an array value in SetVariable you created in step 1.

 

No need to apply to each and additional clutter. Works for me. 

Tomas

Regular Visitor

Re: Convert JSON string to JSON array

Except that method doesn't give me what I'm looking for. Your solution only supplies an array without the necessary JSON key, it just supplies the value. 

Highlighted
Kudo Collector
Kudo Collector

Re: Convert JSON string to JSON array

I was solving the same issue today and I managed to convert the JSON string to JSON array using json() expression.

More details can be found in the link below.

http://persnicketypowerapps.blogspot.com/2018/10/json-operations-in-ms-flow.html

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Users online (5,452)