Parsing array objects in js objects to xml not working

Hey I’m trying to parse a javascript object to xml string in node.js app. I’m using the npm package json2xml like this

json2xml(jsonObject, { header: true });

my issue is that when there’s an array object it will parse it like this:

root: {
    foo: [
        {
            bar: 'a',
        },
        {
            bar: 'b',
        },
    ],
};
<root>
    <foo>
        <bar>a</bar>
        <bar>a</bar>
    </foo>

and not like this:

<root>
    <foo>
        <bar>a</bar>
    </foo>
    <foo>
        <bar>b</bar>
    </foo>
</root>

as I wish it did. Do you have any suggestions or any other libraries I can use to fix this issue?

I’ve tried couple of other libraries: jstoxml, @javadev/xmltojson, fast-xml-parser, that didn’t fix the issue. I’m thinking to write my own jsToXml parser xD