Overview
Convert an XML document into readable JSON: attributes become an @attributes object, repeated sibling elements become arrays, and simple text values are typed automatically as booleans or numbers. Parsing uses the browser's strict XML parser and runs entirely client-side.
How It Works
Paste your XML into the left editor; the JSON tree appears on the right as you type. The root element's name becomes the top-level JSON key. Malformed markup is reported with the parser's own error details rather than producing partial output. Both panels include download buttons for .xml and .json files, and clicking either copies its contents.
Step-by-Step Usage Guide
- Paste the XML document into the left editor.
- Read the JSON on the right; the root tag is the top-level key.
- Fix any parser error shown when markup is not well-formed.
- Copy the JSON or download it as a .json file.
Technical Specifications & Standards
The converter parses with DOMParser in strict XML mode, so parsererror detection catches well-formedness problems that lenient HTML parsing would silently accept. The mapping follows conventions designed for round-tripping: attributes gather under an @attributes key, text content of a leaf element becomes its value, and an element that has both attributes and text keeps the text under #text. Repeated sibling elements with the same tag name merge into an array, so a list of items converts naturally. Leaf text is type-coerced: the literal strings true and false become booleans, and text that parses as a number becomes a number, while everything else stays a string. Three caveats follow. Mixed content loses ordering, because text interleaved with child elements is dropped rather than preserved. Namespaces stay in the keys with their prefixes, so a namespaced element becomes a key like ns:foo. And the conversion is one-way: the site's companion JSON-to-XML tool does not reconstruct @attributes, so a round trip keeps element structure but not attribute placement.
Targeted Use Cases
- Working with XML API responses in JavaScript code that expects objects.
- Migrating legacy XML configuration to JSON format.
- Inspecting an RSS or sitemap document's structure quickly.
- Turning XML fixtures into JSON test data.
Notes & Gotchas
- Check the @attributes objects; attribute values are always strings and are not type-coerced.
- Remember leaf text like 042 becomes the number 42; quote it in the XML if it must stay a string.
- Do not round-trip through the JSON-to-XML tool expecting attributes to survive.
- Keep XML well-formed; the strict parser rejects recoverable mistakes deliberately.
Frequently Asked Questions
Why did the text 8080 become a number?
Leaf text values are auto-typed: true and false become booleans and numeric-looking text becomes a number. Wrap the value to preserve text form if the distinction matters downstream.
Where did my element attributes go?
Attributes are collected into an @attributes object on the element's JSON node. Values remain strings, and an element with both attributes and text keeps the text under #text.
What happens to text mixed between child elements?
When an element has child elements, only the children and attributes are converted; interleaved text is dropped. This keeps the mapping deterministic but is lossy for mixed content.
Why does my key contain a colon?
Namespace prefixes are kept in the JSON keys, so an element named ns:foo stays ns:foo. Strip or remap the prefixes in post-processing if your consumer expects bare names.