cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Villanous81
Helper I
Helper I

Issues with Parse JSON after converting from XML

 
I have been trying for the past 2 days to take an XML from an API and convert to JSON so I can ultimately add to an Excel spreadsheet.

 

I can successfully run a GET call for the API, convert to XML (base64toString conversion), compose the XML, and then compose the JSON. When I attempt to Parse the JSON is when I get errors and I'm not sure how to proceed. Thanks @Jcook  for getting me this far.

 

Base64toString

Villanous81_0-1654617159931.png

 

Convert to XML

Villanous81_1-1654617159947.png

 

XML to JSON

Villanous81_2-1654617159957.png

 

Here is the original XML

Here is how the XML looks after converted to JSON

Using the Output of the JSON compose step, here is the JSON schema

 

This is the error thrown on the Parse JSON step.

2 REPLIES 2
Pstork1
Dual Super User
Dual Super User

This is a common problem when converting from XML to JSON.  The problem is that XML doesn't differentiate between an object and an array.  If an XML tag contains one set of values it will be considered an object, if it contains more than one then it is considered an array.  So if you look at the error message it is complaining that some of your values, which it expects to be arrays are actually strings.  In XML they were a single value inside an opening and closing XML tag.  But in other places in the data set there were multiple strings so those come through as an array.  Look at the simplified XML below

<Tag1>
   <Tag2>"This is a String"</Tag2>
</Tag1>
<Tag1>
 <Tag2>"These are am Array"</Tag2>
 <Tag2>"These are am Array"</Tag2>
</Tag1>

JSON thinks Tag2 should always be an array, but in XML it can be just a string.

 

There is no easy fix for this.  You can change the type in the JSON schema to ["string", "array"] which will clear the error, but then you'll have errors when you try to use the values because strings and arrays operate differently.  So you'll have to check the value each time to figure out which you have before you use it.  

 

Does that all make sense?



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

Yes thank you for the reply, that was the conclusion I came to but was hoping to make sense of this data in some meaningful way. Oh well I'll go at it a different way.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,658)