XML still runs a surprising share of the world — feeds, sitemaps, configuration files, legacy APIs and enterprise integrations — while most modern code prefers JSON. Moving data between those worlds means converting XML to JSON faithfully: elements become keys, repeated elements become arrays, attributes need a home, and text content must not get lost. This converter does that conversion in your browser using the real XML parser, so malformed documents produce a clear error instead of silently wrong output. Paste an XML document, get JSON with attributes preserved under @attributes and text under #text where needed, and copy it into your code, test or migration script. It is the reverse direction of the JSON to XML converter on this site, and together the two tools let you move data either way without installing anything or uploading sensitive payloads.
Quick Answer: Paste an XML document and get clean JSON back, with elements, repeated elements as arrays, attributes and text content preserved.
Free Online Tool
XML to JSON Converter
How to Use the XML to JSON Converter
- Paste your XML document into the input box.
- Press Convert to JSON and read the result.
- Check that repeated elements became arrays and attributes survived.
- If the XML is malformed, read the parser error and fix the fault.
- Copy the JSON into your code, test or migration script.
Key Features
- Real XML parsing in the browser — malformed input is rejected, not guessed
- Repeated elements become JSON arrays automatically
- Attributes preserved under @attributes, text under #text
- Pretty-printed JSON output ready to copy
- Free, instant and entirely in your browser
Best Practices and Tips
- Validate first when a conversion looks wrong: a single unclosed tag invalidates the whole document.
- Remember that XML attributes and child elements are different things; this tool keeps them distinct so nothing is silently merged.
- For feeds and sitemaps, convert a small sample first to confirm the mapping suits your code before converting a large file.
- If your XML uses namespaces, expect prefixed keys in the JSON — strip prefixes in your own code if you do not need them.
- Round-trip check: convert the JSON back with the JSON to XML tool and compare structures to catch mapping surprises.
Common Mistakes to Avoid
- Pasting a fragment without a single root element, which is not a valid XML document.
- Expecting attributes to merge with child elements: they are kept separate by design.
- Ignoring parser errors and hand-editing the output instead of fixing the source XML.
- Assuming element order survives conversion: JSON objects are unordered, so order is not preserved.
Frequently Asked Questions
How are XML attributes represented in JSON?
Attributes are collected under an @attributes key on their element object, so they stay separate from child elements and text. For example, an element with id=”5″ becomes an object containing “@attributes”: {“id”: “5”} alongside its other content.
What happens to repeated elements?
They become arrays. If a document contains three item elements under one parent, the JSON shows item as an array of three objects, which is the natural JSON representation of a repeated structure.
Why did my XML fail to convert?
The browser XML parser rejects malformed documents: unclosed tags, mismatched tags, stray ampersands and missing root elements are the usual causes. The error message points at the fault; fix it in the source and convert again.
Is XML text content preserved?
Yes. When an element has both attributes or children and text, the text is kept under a #text key so it is never lost. Pure text-only elements become simple string values.
Is the XML to JSON converter free?
Yes — free, unlimited and no sign-up required.
Related Tools
- JSON to XML Converter – transforms JSON structures into properly escaped, indented XML
- XML Formatter & Beautifier – pretty-prints, validates and minifies XML safely
- JSON Formatter & Validator – beautifies JSON and pinpoints syntax errors when it will not parse
- JSON to YAML Converter – Convert JSON into clean readable YAML