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