Hi,
I'm using the json funtion to convert from xml with this structure
As you can see, some elements have several children, some have no children and some have only one.
The problem when converting to json is that those who have several children get an array of 'Child' but those with just one child get an object, as seen below:
This causes a problem when formatting the json in the Parse JSON node.
The schema I'm going for is this:
But when trying to parse the json I get this error:
If I change the schema to expect an object, the same thing happens but with reversed.
Is there a way to force the 'Child' nodes to convert always as an array whether there's one or many of them?
I hope I made myself clear.
Thank you in advance.
Solved! Go to Solution.
Hi @AyCN
I did tested this now.
If you add the additional types it should work. Its similar to @Pstork1 suggested.
Here is my test result
If you liked my response, please consider giving it a thumbs up
Proud to be a Flownaut!
Learn more from my blogI don't know of any way to impose a format on the conversion. But you can fix the error in the parse JSON by changing the type to expect either an array or a string value. But that won't really solve the problem since you'll now have to treat each Child value differently when you go to use them. Here's the fix for the JSON schema
"Child": {
"type": [
"array",
"string"
],
"items": { }
}
Hi @AyCN
I did tested this now.
If you add the additional types it should work. Its similar to @Pstork1 suggested.
Here is my test result
If you liked my response, please consider giving it a thumbs up
Proud to be a Flownaut!
Learn more from my blog@abm Adding the additional types is exactly what I recommended. The only problem is that now the Child element may be a string or an array. The rest of the flow will have to deal with that, which could be a problem.
A simpler way to tackle this is to pass the Child element to array function. The array function will parse the string to array of string, if the input is array it is going to return as is. Now you can process the next step considering child is an array.
User | Count |
---|---|
88 | |
39 | |
23 | |
20 | |
16 |
User | Count |
---|---|
128 | |
50 | |
48 | |
35 | |
26 |