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

Turning JSON object elements into array entries in Flow

Hi! I have flow that generates a JSON object of varying size depending on the cirumstances. It follows this pattern, as a string coupled with an integer.

 

{ 
  "J. Smith": 15, 
  "A. Jackson": 55, 
  "W. Gromit": 65
}

 

But depending on the circumstances, this object may have any number of entries and not always three. My wish is to create an array within Flow that lists the names corresponding to a number higher than 50. In this case, an array containing "A. Jackson" and "W. Gromit".

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Turning JSON object elements into array entries in Flow

Hi @ErikPrimozone ,

 

You could refer to screenshot below to create the flow:

1.png2.png

 

Expression in Compose 2:

split(substring(string(outputs('Compose')),1,sub(length(string(outputs('Compose'))),2)),',')

 

Expression in Condition:

int(substring(items('Apply_to_each'),sub(length(items('Apply_to_each')),2),2))

 

Expression in Append to array variable:

substring(items('Apply_to_each'),1,sub(length(items('Apply_to_each')),6))

 

Flow would run successfully as below:

3.png

 

Best Regards,

Alice

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Highlighted
Dual Super User III
Dual Super User III

Re: Turning JSON object elements into array entries in Flow

I'm not sure there is an easier way, but I would do it this way

1) Initialize a JSON string to hold the array with an appropriate prefix for the array

2) Split() the original string into an Array based on the ',' (comma)

3) Do a ForEach Loop where you split each array element based on the ':' (colon) and append the individual array results to a string in JSON fashion with fieldnames.

4) Append the closing JSON array characters to the end of the string.

5) Use Parse JSON to turn the string into a usable JSON array.

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Community Support
Community Support

Re: Turning JSON object elements into array entries in Flow

Hi @ErikPrimozone ,

 

Please take a try with @Pstork1 's solution and if your issue still exists, please let me know and I would provide the details steps with screenshot.

 

Best Regards,

Alice

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Highlighted
Frequent Visitor

Re: Turning JSON object elements into array entries in Flow

Thanks @Pstork1!

 

Hi @v-alzhan-msft. I'm a bit stuck unfortunately, as I'm having toruble properly splitting the Integers into a separate array using "split". I'd appreciate your addition to the solution.

Highlighted
Community Support
Community Support

Re: Turning JSON object elements into array entries in Flow

Hi @ErikPrimozone ,

 

You could refer to screenshot below to create the flow:

1.png2.png

 

Expression in Compose 2:

split(substring(string(outputs('Compose')),1,sub(length(string(outputs('Compose'))),2)),',')

 

Expression in Condition:

int(substring(items('Apply_to_each'),sub(length(items('Apply_to_each')),2),2))

 

Expression in Append to array variable:

substring(items('Apply_to_each'),1,sub(length(items('Apply_to_each')),6))

 

Flow would run successfully as below:

3.png

 

Best Regards,

Alice

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Frequent Visitor

Re: Turning JSON object elements into array entries in Flow

Worked like charm! Thanks, Alice.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (6,171)