Closed Mnemosynel closed 1 year ago
We're glad you find this project helpful. We'll try to address this issue ASAP. You can vist https://solothought.com to know recent features. Don't forget to star this repo.
Hi! I think that's how console.log()
works when printing an array of objects, when the array itself is contained in a nested object.
For example, if you try to print a similar object with this script:
const aaa = {
a:{
b: [ { d: 1 }, { e: 3 } ]
}
}
console.log(aaa);
You obtain
{ a: { b: [ [Object], [Object] ] } }
If you need the object parsed as string you can use JSON.stringify()
.
With your script it should look something like this:
const data = `
<items>
<item>
<name>Item 1</name>
<price>10.99</price>
</item>
<item>
<name>Item 2</name>
<price>19.99</price>
</item>
</items>
`;
function parseOriginFragmentDetail(data: string): any {
const options = {
ignoreAttributes: true,
ignoreNameSpace: true,
parseAttributeValue: false,
parseNodeValue: true,
allowBooleanAttributes: true
};
const parser = new XMLParser(options);
const jsonObj = parser.parse(data);
return jsonObj;
}
let jsonData1 = parseOriginFragmentDetail(data);
console.log(JSON.stringify(jsonData1));
console.log("***************");
You should see this in the console
{"items":{"item":[{"name":"Item 1","price":10.99},{"name":"Item 2","price":19.99}]}}
***************
It works! Thanks!
Description
### Input ```ts const data = `{ items: { item: [ [Object], [Object] ] } }
expected data
Would you like to work on this issue?
Bookmark this repository for further updates. Visit SoloThought to know about recent features.