Open jlguenego opened 6 years ago
In fact it is a nice to have because I can quickly solve it outside of the jsontoxml lib.
function handleArray(js) {
if (js instanceof Array) {
return js.map(n => ({item: n}));
}
if (js instanceof Object) {
const result = {};
for (let p in js) {
result[p] = handleArray(js[p]);
}
return result;
}
return js;
}
in my case i want to embed array items without array key .. for example this is before
<content>
<item>
<lastname>Guénégo</lastname>
<firstname>Jean-Louis</firstname>
</item>
<item>
<lastname>Phengsiaroun</lastname>
<firstname>Dany</firstname>
<item>
</content>
just without the array key
<item>
<lastname>Guénégo</lastname>
<firstname>Jean-Louis</firstname>
</item>
<item>
<lastname>Phengsiaroun</lastname>
<firstname>Dany</firstname>
<item>
Hi @jlguenego:
Just run into this issue today, until I realized from the example in readme that all that's needed is a new object with name and children properties:
let jsonObject = JSON.parse('{"content": [ ... ]}')
let arrayObject = {}
arrayObject.content = jsonObject.content.map(o => Object.assign({name: 'item', children: o})
jsontoxml(arrayObject)
I need to convert the following json into xml:
The output does not satisfy because it does not clearly sepearate the array items:
I would suggest to add in the options something like: handleArrayElement: true
that would produce: