Modify XML to JSON behavior

This is an enhancement of the use case Read XML file contents.

By default, the xml node, powered by the xml2js library, wraps all XML elements in arrays, even if they occur only once. For example:

<CustomerNumber>CU63190739</CustomerNumber>

becomes:

"CustomerNumber": ["CU63190739"]

This ensures consistency and predictable output, allowing you to use the same access pattern regardless of whether a node appears once or multiple times.

If you prefer plain key-value pairs and want to avoid single-value arrays, you can disable this behavior.

The easiest way to do this is by adding a change node after the read file node and before the xml node. Set the msg.options.explicitArray property of the change node to false.

Alternatively, you can achieve the same result in a function node, using this code:

msg.options = { explicitArray: false };

return msg;

You can build on this flow to write data values to a custom property, as shown in the next use case, Write data values to custom property.