What is XML to JSON?
Converting XML to JSON means reading a markup document and rebuilding the same information as JSON data: elements become keys, their text becomes values, and nesting becomes nesting.
It is the harder direction of the two. Going from JSON to XML, every JSON construct has somewhere to go. Coming back, XML carries three things JSON has no slot for — attributes, mixed content, and the difference between one child and a list of one — so a converter has to invent conventions. Every XML-to-JSON tool invents slightly different ones, which is why the same document converted by two tools rarely matches.
<user id="1042"> <name>Ada Lovelace</name> <city>London</city></user>{ "user": { "@id": "1042", "name": "Ada Lovelace", "city": "London" }}Two decisions are already visible. The id attribute became @id, marking it as having come from an attribute rather than a child element — because otherwise it would be indistinguishable from <id>1042</id>. And "1042" is a string, not a number, because XML never said it was one.