cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cmiller2784
Advocate I
Advocate I

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
Advocate I
Advocate I

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

5 REPLIES 5
cmiller2784
Advocate I
Advocate I

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

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

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. 

LinnZawWin
Kudo Kingpin
Kudo Kingpin

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

Thank you so much!!!

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

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Users online (2,018)