Free Online XML to JSON Converter
The XML to JSON Converter turns XML documents into clean JSON. Attributes, nested elements, and repeated tags are handled so arrays and objects come out the way you would expect.
The reverse direction is not a direct conversion, but the JSON Formatter & Beautifier makes the result readable and the JSON Validator confirms it parses. For XML that is markup rather than data, the XML Formatter & Beautifier is the tool.
How to use the XML to JSON
- 1 Paste your XML.
- 2 Convert. Elements become keys, attributes are handled according to the setting you choose.
- 3 Check how repeated elements were represented, since the choice affects everything downstream.
- 4 Copy the JSON.
What the conversion cannot preserve
XML is a document format with a rich model: namespaces, attributes, mixed content, comments, processing instructions and significant order. JSON is a data format with objects, arrays and scalars. Converting between them is a lossy operation, and the losses are structural rather than incidental.
For data-oriented XML — records, configs, API payloads — the conversion is clean and useful. For document-oriented XML, the right answer is often not to convert, because the resulting JSON will be awkward to use and will have discarded the very structure that made the original meaningful.
- Namespaces have no JSON equivalent and need flattening.
- Attributes require a naming convention to avoid collisions.
- Repeated elements become arrays; deciding the rule matters.
- Element order and comments are not preserved.
Frequently asked questions
How are attributes and text content represented?
There is no standard, so the convention has to be chosen. Attributes are commonly prefixed to distinguish them from child elements, or nested under a dedicated key. Mixed content — text and elements together inside one element — is the genuinely hard case, because JSON has no equivalent and the text has to be given a key.
What happens with repeated sibling elements?
They become an array, which is usually what you want. The ambiguity is when there is only one instance: it is impossible to know whether the schema allows more, so a naïve converter produces an object for one and an array for many. That inconsistency breaks consumers, and the usual fix is a setting that always uses arrays for such elements.
Why does the order of elements change?
Because JSON objects are formally unordered, so element order cannot be preserved in the general case. If order carries meaning in the source — as it does in a document rather than a data file — the conversion loses information that no amount of care can retain.
Related Developer Tools
You might also need
Tools from other categories that people pair with the XML to JSON: