Two data models that do not quite line up
Converting XML to JSON looks mechanical and is not, because the two formats can express things the other cannot.
XML has attributes, which JSON has no equivalent of. XML distinguishes an element with one child from an element with several, whereas JSON needs to decide upfront whether something is an array. XML allows text and elements to interleave inside one parent, which JSON cannot represent at all. JSON has real number and boolean types, which XML does not.
Every converter therefore makes a set of choices, and different libraries choose differently, which is why two converters can give you different JSON from the same XML. The choices made here are set out below rather than left for you to reverse engineer from the output.
Converting
- Choose a Direction.
- For XML to JSON, choose an Attribute handling, XML to JSON only mode.
- Set an Indent size in spaces.
- Paste your document and run it.
The attribute problem, and the two answers
An attribute and a child element are different things in XML and become the same thing, a key, in JSON. Something has to distinguish them.
Prefix mode marks each attribute’s key with an at sign. It is unambiguous, it survives a round trip because the marker identifies which keys were attributes, and it is slightly ugly to read.
Merge mode drops the marker so attributes sit alongside child keys as ordinary properties. It reads better and it carries a genuine hazard: if an attribute and a child element share a name, they collide, and the child element wins because attributes are written first and the child overwrites them. The attribute value is gone, silently.
That is not a bug so much as an unavoidable consequence of merging two namespaces into one, and it is why prefix is the default. Choose merge when you know your document has no such collisions and you want the JSON to read cleanly.
When a single element becomes an array
Repeated siblings with the same tag under one parent become an array in document order. That is what makes a feed of items or a list of records convert into something usable.
A tag appearing only once stays a bare value. This is the choice worth knowing about, because some converters always produce arrays so that consuming code never has to check. That consistency is genuinely valuable when you are writing a parser, and it makes the common case, a document where most elements appear once, considerably noisier to read.
The practical consequence is that consuming code has to handle both shapes. If your feed happens to contain exactly one item, that key is an object rather than a one element array.
Going back the other way
JSON to XML inverts the mapping, and it imposes two requirements that come straight from XML’s own rules.
The top level must be an object with exactly one key, since that key names the root element and a document can have only one root. An object with three keys is refused with a message naming how many were found, and a top level array is refused for the same reason.
A key beginning with an at sign is always written out as an attribute in this direction, regardless of which attribute mode is selected, since the mode only affects the other direction. That is what makes a prefix mode round trip work.
What does not survive
Comments, processing instructions, the document type declaration and the XML prolog are dropped. JSON has nowhere to put them and this is a data converter.
Mixed content is the other casualty. Text interleaved between child elements, as in a sentence with markup inside it, has all its text nodes concatenated into a single value, so their positions relative to the elements are lost. Configuration files, API payloads and feeds essentially never use that pattern, which is why the trade is acceptable here.
If you need the document preserved rather than converted, XML Formatter reformats it without discarding anything.
Related conversion tools
For the other direction of the configuration world, YAML to JSON converts the format that has largely replaced XML for config. To make the resulting JSON readable, JSON Formatter pretty-prints and validates it, and JSON to CSV flattens it into a table.
For data that started life in a spreadsheet, Excel to JSON is the entry point, and Diff Text compares two converted outputs. The rest are on the dev tools hub.

