XML to JSON Converter (and Back)

Convert XML to JSON and JSON to XML in your browser. Attributes map to @-prefixed keys; text content to #text.

About this tool

XML and JSON are both hierarchical data formats, and converting between them is common when bridging older XML-based APIs or config with modern JSON tooling. This converter parses XML using the browser’s built-in DOMParser — the same engine the browser uses — so it handles real-world XML robustly, then maps it to JSON with a clear convention: element attributes become keys prefixed with @, and an element’s text content becomes #text. Repeated child elements collapse into a JSON array. The reverse direction serializes a single-rooted JSON object back into indented XML using the same conventions. Everything runs locally in your browser, keeping your data private. Note that XML and JSON do not map perfectly — mixed content and namespaces are simplified — so review the output for complex documents.

How to use it

  • Choose XML → JSON or JSON → XML.
  • Paste your document.
  • Click Convert.
  • Copy the output; attributes are @-prefixed and text is under #text.

Frequently asked questions

How are XML attributes represented in JSON?
Each attribute becomes a key prefixed with @. For example, <book id="1"> becomes { "book": { "@id": "1", ... } }. This keeps attributes distinct from child elements in the JSON structure.
What happens to an element’s text content?
If an element has both attributes/children and text, the text is placed under a "#text" key. If it has only text and no attributes, it becomes a plain string value for simplicity.
How are repeated elements handled?
When an element appears multiple times under the same parent (e.g. several <tag> elements), they are collapsed into a JSON array, preserving order. A single occurrence stays as a single object/value.
Why might XML and JSON not round-trip perfectly?
The two models differ: XML has ordered mixed content, namespaces, comments, and processing instructions that JSON lacks. This converter targets the common data subset, so exotic XML features are simplified or dropped.
Does JSON → XML need a specific shape?
Yes — the JSON must have exactly one root key (the root element name). Use @-prefixed keys for attributes and #text for inline text to mirror the XML → JSON convention.
Is my data uploaded?
No. Parsing and serialization happen entirely in your browser via DOMParser and local code; nothing is sent to a server.

Related tools