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>
Thank you very much. This is exactly what I need.
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:
We can use this flow:
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
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?
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:
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