cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Setting Parameter Name for JSON

Hi there,

 

I'm having difficulty "attaching" a name (parameter) to this JSON data. I need to call it so I need it to look like the bottom. So for example, rather than jut having:

 

[
  "Steel slab",
  "Example Slab"
]

 

 I need it to look like:

 

[
  "Product1": Steel slab,
  "Product2": Example Slab
]

 

ProfileCrater3_0-1614865415753.png

 

 

{ 
 "AdditionalDetails": {
    "CommercialNames": [
      "Steel slab",
      "Example Slab"
    ],
    "Comments": null,
    "AssociationCode": null,
    "ApplicationSuitability": "y",
    "NationalSecurity": "y"
  },
  "SourceCountries": [
    {
      "OriginCountry": "Brazil",
      "ExportCountry": "Brazil",
      "ExclusionQty": "8000000",
      "Manufacturer": "A.",
      "Supplier": null
    }
}

 

 Hope this makes sense!

1 ACCEPTED SOLUTION

Accepted Solutions
v-yiwenxie-msft
Microsoft
Microsoft

Hi @Anonymous 

 

I’ve made a test and have run it successfully.

 

My input is:

3.9-7.PNG

 

My output is:

3.9-8.PNG

 

The following flow is for your reference:

3.9-6.PNG

 

The detailed steps for ‘initialize variable’:

3.9-9.PNG

 

The detailed steps for ‘Apply to each’:

3.9-11.PNG

The ‘Value’ in ‘Append to array variable’:

{

  "product@{variables('index')}": "@{items('Apply_to_each')}"

}

 

The detailed steps for these ‘Compose’:

3.9-12.PNG

‘Compose 2’:

string(variables('products'))

 

‘Compose 3’:

replace(outputs('Compose_2'),'},{',',')

 

‘Compose 4’:

json(outputs('Compose_3'))

 

For more info about the functions above:

 

The step ‘Compose 5’ shows you an example of how to reference the product1:

3.9-13.PNG

‘Compose 5’:

outputs('Compose_4')[0]['product1']

 

[0] is used to get the first item in an array, [1] is used to get the second item in an array, and so on.

Because in ‘Compose 4’, there is only one item in the array. So here should use [0].

You can input product2/3/4… in the place of ‘product1’.

 

The outputs of ‘Compose 4’ and ‘Compose 5’:

3.9-14.PNG

 

If you still have the problem, please feel free to let me know.

 

Best Regards,
Community Support Team _ Kira Xie
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
abm
Super User III
Super User III

Hi @Anonymous 

 

Please follow this post.

 

Solved: Convert JSON string to JSON array - Power Platform Community (microsoft.com)

 

If you need any further help please let me know.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials
Anonymous
Not applicable

@abm Thanks for replying! Good resource but I keep getting an error:

 

split(outputs('CommericalNames'),',')

 

ProfileCrater3_0-1614872332824.png

 

abm
Super User III
Super User III

In your case you don't need to use the split. You can iterate the array using the below.

 

image.png

 

Expression I used above inside the apply to each loop is 

 

item()

 

Once you have the item you can construct the JSON elements which is already mentioned in that link.

 

Thanks

 

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials
v-yiwenxie-msft
Microsoft
Microsoft

Hi @Anonymous 

 

I’ve made a test and have run it successfully.

 

My input is:

3.9-7.PNG

 

My output is:

3.9-8.PNG

 

The following flow is for your reference:

3.9-6.PNG

 

The detailed steps for ‘initialize variable’:

3.9-9.PNG

 

The detailed steps for ‘Apply to each’:

3.9-11.PNG

The ‘Value’ in ‘Append to array variable’:

{

  "product@{variables('index')}": "@{items('Apply_to_each')}"

}

 

The detailed steps for these ‘Compose’:

3.9-12.PNG

‘Compose 2’:

string(variables('products'))

 

‘Compose 3’:

replace(outputs('Compose_2'),'},{',',')

 

‘Compose 4’:

json(outputs('Compose_3'))

 

For more info about the functions above:

 

The step ‘Compose 5’ shows you an example of how to reference the product1:

3.9-13.PNG

‘Compose 5’:

outputs('Compose_4')[0]['product1']

 

[0] is used to get the first item in an array, [1] is used to get the second item in an array, and so on.

Because in ‘Compose 4’, there is only one item in the array. So here should use [0].

You can input product2/3/4… in the place of ‘product1’.

 

The outputs of ‘Compose 4’ and ‘Compose 5’:

3.9-14.PNG

 

If you still have the problem, please feel free to let me know.

 

Best Regards,
Community Support Team _ Kira Xie
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

Anonymous
Not applicable

Thank you! @v-yiwenxie-msft @abm 

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

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.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (1,287)