ArrayMode Support
See original GitHub issueArray mode is the most wanted feature in XML to JSON parser. Check the example to understand the need;
<report>
<store>
<region>US</region>
<inventory>
<item>
<name>Banana</name>
<count>200</count>
</item>
<item>
<name>Apple</name>
<count>100</count>
</item>
</inventory>
</store>
<store>
<region>EU</region>
<inventory>
<item>
<name>Banana</name>
<count>100</count>
</item>
</inventory>
</store>
</report>
Parsed response
{
"report": {
"store": [
{
"region": "US",
"inventory": {
"item": [
{
"name": "Banana",
"count": "200"
},
{
"name": "Apple",
"count": "100"
}
]
}
},
{
"region": "EU",
"inventory": {
"item": {
"name": "Banana",
"count": "100"
}
}
}
]
}
}
When the occurence of a tag is 1 it is parsed as an objectg otherwise array. In this case, user need an extra check to traverse through the parser response to confirm if he value of a tag is array type or object type.
I have solved this problem by introducing arrayMode
option.
const jsObj = parser.parse(xmlData, {
arrayMode: true
});
When arrayMode: true
, it parses all tags as array if they have nested tags.
{
"report": [
{
"store": [
{
"region": "US",
"inventory": [
{
"item": [
{
"name": "Banana",
"count": 200
},
{
"name": "Apple",
"count": 100
}
]
}
]
},
{
"region": "EU",
"inventory": [
{
"item": [
{
"name": "Banana",
"count": 100
}
]
}
]
}
]
}
]
}
When arrayMode: 'strict'
, it parses all tags as array.
{
"report": [
{
"store": [
{
"region": ["US"],
"inventory": [
{
"item": [
{
"name": ["Banana"],
"count": [200]
},
{
"name": ["Apple"],
"count": [100]
}
]
}
]
},
{
"region": ["EU"],
"inventory": [
{
"item": [
{
"name": [ "Banana" ],
"count": [100]
}
]
}
]
}
]
}
]
}
It’ll look like as follow in case of node text, attribute, and CDATA
"item": [
{
"#text": "some item detail",
"@_grade": "A",
"name": "Banana",
"count": 200
},
{
"@_grade": "B",
"__cdata": "som text",
"name": "Apple",
"count": 100
}
]
or in strict mode
"item": [{
"#text": [ "some item detail" ],
"@_grade": [ "A" ],
"name": [ "Banana" ],
"count": [ 200 ]
},{
"@_grade": [ "B" ],
"__cdata": [ "som text" ],
"name": [ "Apple" ],
"count": [ 100 ]
}
]
Please let us know if you think that the parsing output should be different.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ArrayMode (POI API Documentation) - Apache POI
Interface for those functions that evaluate arguments in array mode depending on context. Skip navigation links. Overview · Package; Class; Use · Tree ......
Read more >parsing a particular tag as array using fast-xml-parser in NodeJs
I used this arrayMode: tagName => ['Item', 'Transaction'].includes(tagName) and it worked. – ShailendraChoudhary. Apr 23, 2021 at 6:34.
Read more >CData JDBC Driver for Domino - ArrayMode - CData Software
CData JDBC Driver for Domino - RSBDomino - ArrayMode: How fields that contain array values are presented.
Read more >What is Panel Array Mode | ATEN Corporate Headquarters
Manage multiple over IP servers on one screen with ATEN's Panel Array Mode™. The technology now provides capabilities in production line, surveillance. banner....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It worked well for my 800MB file, thx 😃
@LihiJosef Try isArray option of FXPv4.