Say your XML file is:
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
</CD>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
</CD>
If you transform it into JSON, should it be (version 1):
{
"CATALOG": {
"CD": [
{
"ARTIST": "Bob Dylan",
"TITLE": "Empire Burlesque"
},
{
"ARTIST": "Bob Dylan",
"TITLE": "Empire Burlesque"
},
]
}
}
Or (version 2):
{
"CATALOG": [
{
"CD": {
"ARTIST": "Bob Dylan",
"TITLE": "Empire Burlesque"
}
},
{
"CD": {
"ARTIST": "Bob Dylan",
"TITLE": "Empire Burlesque"
}
}
]
}
My feeling is that version 1 is more correct but I'm wondering if there is a norm?
Thanks for your feedback - Christian
It depends on what you mean by more correct.
Both Version 1 and Version 2
JSON
formats above are valid under RFC 8259.JSON
with it here.However, with that said, most online
XML
toJSON
converters (like this one here) would handle the conversion with Version 1. Making it more compact and readable (and easy to consume).