web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Automate
Answered

Transform Array

(0) ShareShare
ReportReport
Posted on by 6,048 Super User 2024 Season 1

Hello Community,

 

I have this array:

[
  {
    "crd6a_set_w_flow_low_bypass_time""300"
  },
  {
    "crd6a_ismodified""true"
  },
  {
    "crd6a_set_med_bank_press_max""80.3"
  },
  {
    "crd6a_set_low_bank_press_max""256"
  }
]
 
 
I want to convert it to this:
 
[
  {
    "crd6a_set_w_flow_low_bypass_time""300",
 
    "crd6a_ismodified""true",
 
    "crd6a_set_med_bank_press_max""80.3",
 
    "crd6a_set_low_bank_press_max""256"
  }
]
Categories:
I have the same question (0)
  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    I'm sure there's an easier way to how I've done it, but it works.

     

    See full flow below. I'll go into each of the actions.

    grantjenkins_4-1672662571962.png

     

    Data is a Compose that contains your data.

    grantjenkins_1-1672662357965.png

     

    XML is a Compose that converts your JSON data to XML so we can use XPath. Note that it also adds a root element to ensure it's valid XML. The expression used is:

    xml(json(concat('{"root": { value:', outputs('Data'), '}}')))

    grantjenkins_2-1672662427478.png

     

    This will give us the following XML output.

    <root>
     <value>
     <crd6a_set_w_flow_low_bypass_time>300</crd6a_set_w_flow_low_bypass_time>
     </value>
     <value>
     <crd6a_ismodified>true</crd6a_ismodified>
     </value>
     <value>
     <crd6a_set_med_bank_press_max>80.3</crd6a_set_med_bank_press_max>
     </value>
     <value>
     <crd6a_set_low_bank_press_max>256</crd6a_set_low_bank_press_max>
     </value>
    </root>

     

    Initialize variable data creates a new variable called data of type Object set initially with an empty object. This will eventually contain your single object with all the properties.

    grantjenkins_3-1672662481170.png

     

    Apply to each iterates through each of the properties within your objects using the following XPath expression.

    xpath(outputs('XML'), '//value/*')

    grantjenkins_5-1672662616150.png

     

    Add Property is a Compose that adds each of the properties and values to the data object. It uses the following expression to get the name and value and add them.

    addProperty(variables('data'), xpath(items('Apply_to_each'), 'name(//*)'), xpath(items('Apply_to_each'), 'string(//*/text())'))

    grantjenkins_6-1672662693500.png

     

    Set variable data then sets the new output to our data variable.

    grantjenkins_7-1672662726487.png

     

    Finally, Compose displays the contents of our data object.

    grantjenkins_8-1672662840766.png

     

    After running the flow, we get the following output.

    grantjenkins_9-1672662925591.png


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • zmansuri Profile Picture
    6,048 Super User 2024 Season 1 on at

    Awesome!!!

  • Chriddle Profile Picture
    8,443 Super User 2025 Season 2 on at

    You can also do this with string operations (with only one action):

     

    Compose:

    [
     {
     "crd6a_set_w_flow_low_bypass_time": "300"
     },
     {
     "crd6a_ismodified": "true"
     },
     {
     "crd6a_set_med_bank_press_max": "80.3"
     },
     {
     "crd6a_set_low_bank_press_max": "256"
     }
    ]

     

    Compose 2 expression:

    json(
    	replace(
    		substring(
    			string(outputs('Compose')),
    			1,
    			sub(
    				length(string(outputs('Compose'))),
    				2
    			)
    		),
    		'},{',
    		','
    	)
    )

     

    Output of Compose 2: 

    {
     "crd6a_set_w_flow_low_bypass_time": "300",
     "crd6a_ismodified": "true",
     "crd6a_set_med_bank_press_max": "80.3",
     "crd6a_set_low_bank_press_max": "256"
    }

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard