cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
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
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
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

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

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 Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 373 members 4,817 guests
Please welcome our newest community members: