Skip to main content

Notifications

Power Automate - General Discussion
Answered

How to convert XML to JSON

(0) ShareShare
ReportReport
Posted on by 25

Hi,

I am a new user. Can anyone help me how to convert XML data to JSON? or how to refer to parameters in XML?

<Positions>
	<Positions id="1699271935983345" idBox="9118" positionLatitude="51.80883" positionLongitude="108.84533" address="SE, address" asimuth="186" velocity="0" fuelLevel="12" engineOn="0" distanceTotal="54555" fuelConsumptionTotal="" idTrailer="" idDriver="" timeStamp="2023-10-06 11:59:53"/>
	<Positions id="1699271935808563" idBox="9631" positionLatitude="52.82442" positionLongitude="109.01721" address="PL, address" asimuth="96" velocity="69" fuelLevel="45" engineOn="0" distanceTotal="445666" fuelConsumptionTotal="" idTrailer="" idDriver="" timeStamp="2023-10-06 11:57:54"/>
	<Positions id="1699271935740443" idBox="9733" positionLatitude="53.89404" positionLongitude="93.07141" address="BE, address" asimuth="252" velocity="44" fuelLevel="35" engineOn="1" distanceTotal="706237" fuelConsumptionTotal="285498" idTrailer="" idDriver="" timeStamp="2023-10-06 11:56:52"/>
</Positions>

 

  • Lukinfo Profile Picture
    Lukinfo 25 on at
    Re: How to convert XML to JSON

    Thank you very much. This is exactly what I need.

  • Verified answer
    Re: How to convert XML to JSON

    Hi , @Lukinfo 

    Thanks for your quick response , sorry for i am not surely understand " the input data did not look like I wrote" ,in the above reply i just copy your xml in my function,and do you mean you want to get the  individual elements in a loop?

    You can try to use the "Apply to each" action in flow:
    For example , this is the json:

    vyueyunmsft_0-1699434495095.png

    We can use this flow:

    vyueyunmsft_1-1699434596333.png

    Then we can get the "@id" in a loop.

     

     

    If I misunderstand what you mean, you can describe your needs and your expected outcomes in detail so that we can better help you.


    Best Regards,

    Yueyun Zhang

     

  • Lukinfo Profile Picture
    Lukinfo 25 on at
    Re: How to convert XML to JSON

    Thank you very much for your answer. I noticed that the input data did not look like I wrote, hence my problems, but thank you anyway. Can you help me how to refer to individual elements in a loop?

  • Verified answer
    Re: How to convert XML to JSON

    Hi , @Lukinfo 

    If you want to convert the xml to json in Power Automate you just need to use this:

     

    json(xml('<Positions>
    	<Positions id="1699271935983345" idBox="9118" positionLatitude="51.80883" positionLongitude="108.84533" address="SE, address" asimuth="186" velocity="0" fuelLevel="12" engineOn="0" distanceTotal="54555" fuelConsumptionTotal="" idTrailer="" idDriver="" timeStamp="2023-10-06 11:59:53"/>
    	<Positions id="1699271935808563" idBox="9631" positionLatitude="52.82442" positionLongitude="109.01721" address="PL, address" asimuth="96" velocity="69" fuelLevel="45" engineOn="0" distanceTotal="445666" fuelConsumptionTotal="" idTrailer="" idDriver="" timeStamp="2023-10-06 11:57:54"/>
    	<Positions id="1699271935740443" idBox="9733" positionLatitude="53.89404" positionLongitude="93.07141" address="BE, address" asimuth="252" velocity="44" fuelLevel="35" engineOn="1" distanceTotal="706237" fuelConsumptionTotal="285498" idTrailer="" idDriver="" timeStamp="2023-10-06 11:56:52"/>
    </Positions>'))

     

     

    Then the result is as follows:

    vyueyunmsft_0-1699432845575.png

     

    For this , you can also refer to :
    Reference guide for expression functions - Azure Logic Apps | Microsoft Learn

     

    If I misunderstand what you mean, you can describe your needs and your expected outcomes in detail so that we can better help you.


    Best Regards,

    Yueyun Zhang

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,508

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,839

Leaderboard