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."
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.
And what's weirder, is if I generate the Schema to expect an array by enclosing the output of Compose Action in []...
... I get the OPPOSITE error: "Expected Array but got Object".
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"?
Solved! Go to Solution.
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.
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.
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.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
Did you know that you could restore a deleted flow? Check out this helpful article.
User | Count |
---|---|
32 | |
31 | |
24 | |
24 | |
20 |
User | Count |
---|---|
59 | |
57 | |
43 | |
37 | |
28 |