cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DaveConnors
Frequent Visitor

Parse JSON always returning an error

I am getting a very frustrating issue with the Parse JSON action.

My flow is checking if a particular file is added to a folder, then extracts the XML from that file with one Compose Action, then converts that to JSON  with another Compose action.

 

When I take the output of the second Compose action and use that to generate a schema in Parse JSON, i get an error saying "Expected Object but got Array."

 

Object Array Error.png

 

Now, I've checked the output of the Compose JSON Step and it's definitely NOT an Array. The JSON output has confidential info and has over 3k records in it so I can't post the whole record here but if you see the start it's definitely an Object and not an array.

 

JSON Start.png

 

And what's weirder, is if I generate the Schema to expect an array by enclosing the output of Compose Action in []...

Array Schema.png

 

... I get the OPPOSITE error: "Expected Array but got Object".

 

Array Object Error.png

 

In both cases, the source file and the output of the JSON Compose action is identical, the only difference is whether i added [] to the sample payload when generating the schema.

How can it possibly be that in one case it's failing with "Expected Object but got Array" but when I told it to expect an Array it failed with "Expected Array but got Object"?

1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User
Dual Super User

The error is a type error.  So I suspect the problem is that you have elements in the JSON that are sometimes objects and sometimes an array of objects.  That can definitely happen when converting XML to JSON.  The problem is that XML isn't consistent in requiring a parent (array) element when including multiple elements.  So you may have output that looks like this

<root>

<item1>

<attribute>

</attribute>

<item1>

<item2>

<attribute>

</attribute>

<attribute>

</attribute>

<item2>

</root>

Attribute will translate to an object in JSON for Item1 and an array for Item2.  I think that is what is happening to you.

 



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

View solution in original post

3 REPLIES 3
Pstork1
Dual Super User
Dual Super User

The error is a type error.  So I suspect the problem is that you have elements in the JSON that are sometimes objects and sometimes an array of objects.  That can definitely happen when converting XML to JSON.  The problem is that XML isn't consistent in requiring a parent (array) element when including multiple elements.  So you may have output that looks like this

<root>

<item1>

<attribute>

</attribute>

<item1>

<item2>

<attribute>

</attribute>

<attribute>

</attribute>

<item2>

</root>

Attribute will translate to an object in JSON for Item1 and an array for Item2.  I think that is what is happening to you.

 



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

Ok, thanks.

I think what you say is certainly possible given my understanding of the original data

Is there any solution? 

@Pstork1 so in the schema I updated every instance of 'type: "object",' to 'type: ["object", "array"]," and this is now working.

 

For some reason I was thinking of the overall payload as object or array, hadn't considered the actual items in it the payload. Thanks so much for the pointer.

Helpful resources

Announcements
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.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

Users online (3,796)