cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cmiller2784
Level: Powered On

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
cmiller2784
Level: Powered On

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

1 REPLY 1
Highlighted
cmiller2784
Level: Powered On

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

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (6,536)