XML to JSON Converter – Free, Online, Private
Read an XML document into JSON. Attributes keep an @ prefix, repeated sibling tags become arrays, and text is coerced when it is a number or boolean.
How to convert XML to JSON
- Paste a single XML document. The declaration and comments are skipped.
- The converter builds a tree and prints JSON under the root element name.
- Copy the JSON. Repeated elements such as <book> become an array.
What the tree looks like
The JSON root is an object with one key, the document element. Attributes are keys prefixed with @ so they cannot collide with a child element of the same name. If an element has only text, the value is that text, coerced to a number or boolean when the whole string matches. If it has children, the value is an object. Sibling elements that share a tag name are grouped into an array, which is the only way JSON can represent two <book> nodes. Mixed content, text plus children, stores the text under #text. Comments and the XML declaration are dropped.
What is intentionally not supported
This is not a full XML stack. DTDs are not loaded, so entity expansion attacks have nothing to fetch, but undeclared entities other than the five built-in ones will not be resolved. Namespaces are preserved as part of the tag string rather than rewritten into a Clark notation. CDATA is treated as text if it appears as character data the scanner sees; a CDATA section is not a separate node type. Processing instructions are skipped only when they use the declaration form. If the file has two top-level elements, the parser reports unexpected content after the root.
Worked example
The sample catalog has two book children. Because the tag repeats, book is a JSON array of length two. Each book has @id from the attribute and title plus author from child elements. Those children contain only text, so their values are strings. id stays a string on the attribute because attributes are not coerced; title text that is purely numeric would become a number. That split is useful for ids you do not want to lose leading zeros on, and surprising for counts stored as attributes. Move the value to element text if you want coercion.
Privacy and size
Parsing happens locally. A multi-megabyte feed will use memory in the tab and nowhere else. For a one-shot conversion of a partner's XML invoice this is the point: the invoice never hits a conversion API. After you have JSON, the JSON formatter, the CSV converter or the SQL insert builder on this site can take the next step without a second upload.
Frequently asked questions
Why do attributes start with @?
So an attribute and a child element can share a name. The JSON to XML converter understands the same prefix and writes those keys back as attributes.
Why is one book an object and two books an array?
A single child stays an object so simple documents are not wrapped needlessly. A repeated tag becomes an array. Consumers should accept both or normalize.
Are namespaces removed?
No. The prefix stays in the key. xmlns attributes appear as @xmlns.
Can I convert an RSS feed?
Yes, if it is well-formed XML. You will get channel, item arrays and the usual text fields. HTML stuffed inside a description stays a string.