XML to JSON Explicit Array only on the highest level

Hi all,

I have a XML that I need to process. Sometimes I have multiple records and sometimes I only have one. When I have multiple records all is good.

But when I only have one and try to use the item node to split into Items it goes wrong.
image
As it is not an array so it gives an error.
image

I saw I can sorta fix this by changing it to make an explicit array with the XML → JSON node.

But it transforms all values into arrays. Where I just need one level to be an array.
XML as received:

Is there any way I can configure this Node to only have a specific level made into an array?

n8n version .151

Hi @anon87652862, the simplest way I can think of would be to use JavaScript’s .concat() before the Item Lists node. This method accepts both single objects and arrays but will always return an array (which is what is expected by the Item Lists node in your example).

Here is an example using the Function Item node to run .concat:

Example Workflow

Hi @MutedJam
Thanks!
I expected that there should be an easy way to fix this.
This works perfectly.

1 Like