JSON ⇄ XML: what it does and how to use it
Table of contents
JSON and XML both describe nested data, but they are not equivalent, and the differences are what make conversion interesting. XML elements can carry attributes; JSON objects cannot. XML has no arrays - repetition is just the same tag appearing twice - while JSON distinguishes a one-item array from a bare value. XML has no types at all, so every value arrives as text. This converter handles the common case well: it turns JSON objects into nested elements, escapes characters that would break the markup, and collapses repeated XML tags back into JSON arrays. Where it is deliberately simple is attributes - converting XML to JSON reads element content and ignores attributes, so if your source keeps real data in attributes rather than child elements, you will need to move it first. That covers most API payloads and config files; it does not cover attribute-heavy document XML. Everything is converted in your browser.
You should not have to open an IDE to format a snippet from Slack, tidy a JSON blob, or check a hash. Paste it here, copy the result, move on.
JSON ⇄ XML is a good fit when feeding a legacy SOAP or enterprise XML response into a modern JSON codebase.
The useful part
JSON ⇄ XML is built around a few practical wins, not a long feature list:
- Handles the awkward parts: XML escaping, repeated tags becoming arrays, and nested objects becoming nested elements.
- Reports parse errors instead of silently emitting broken output.
- Swap converts in the opposite direction so you can inspect a round trip immediately.
- Runs entirely in your browser - useful because API payloads usually contain real customer data.
- No upload, no account, no size limit beyond your own memory.
Do this, in order
- Pick a direction. JSON to XML, or XML to JSON. The swap button feeds the output back as input to check a round trip.
- Paste your data. Both sides validate as you convert - malformed input reports a parse error rather than producing wrong output.
- Review the structure, not just the syntax. Check arrays and any attributes specifically, since these are where the two formats genuinely disagree.
- Copy the result. Fix up types and attributes by hand if the target system needs them.
Who it is for
- Feeding a legacy SOAP or enterprise XML response into a modern JSON codebase.
- Converting a JSON fixture into XML to test an older integration.
- Turning an RSS or sitemap fragment into JSON to inspect it.
- Reformatting config between an XML-based tool and a JSON-based one.
- Making an XML payload readable by viewing it as JSON.
If you want a clean result
- If your XML keeps data in attributes, rewrite them as child elements before converting - attributes are not read.
- Remember every value from XML comes back as a string. "42" and "true" will need converting to number and boolean yourself.
- A JSON array with exactly one item does not survive the round trip: it becomes a single element, which reads back as an object rather than an array. Handle that in code if it matters.
- JSON keys containing spaces, dots or other characters illegal in XML tag names are replaced with underscores, since the alternative would be invalid XML.
- Convert a small representative sample first and check the shape before running your whole dataset through.
Common mix-ups
- Expecting XML attributes to appear in the JSON output - only element content is read, so attribute data is dropped.
- Assuming types survive. XML has no type system, so numbers and booleans return as strings.
- Relying on an exact round trip for single-item arrays, which XML cannot represent distinctly.
- Sending confidential payloads through a server-based converter when this one does not need to - check where any online converter runs before pasting production data.
- Ignoring namespaces: prefixed tag names come through as part of the key, so a namespaced document needs review rather than blind conversion.
Private by default
JSON ⇄ XML runs in your browser. The file or text you paste stays on your device. There is no account, and nothing is stored on a ToolBox server for this job.
Related tools worth opening next
If this is one step in a longer job, these usually come after it:
- XML Formatter - Format, validate and minify XML documents
- JSON Formatter - Format and validate JSON data
- YAML ⇄ JSON - Convert between YAML and JSON formats
Before you ask
Does it convert XML attributes into JSON?
No. XML to JSON reads element content only, so attributes are not included in the output. If your data lives in attributes, restructure them as child elements first. This keeps the output predictable for API payloads and config files, where nested elements are the norm.
Will a JSON to XML to JSON round trip return identical data?
For nested objects and multi-item arrays, yes in structure. Two things change: all values come back as strings because XML is untyped, and an array with a single item comes back as an object, because a lone repeated tag is indistinguishable from a plain child element.
How are XML namespaces handled?
Prefixed tag names such as soap:Body come through with the prefix as part of the JSON key. The xmlns declarations themselves are attributes, so they are not carried over - a heavily namespaced document will convert, but review the result rather than trusting it blindly.
What happens to JSON keys that are not valid XML tag names?
Characters that XML does not allow in a tag name - spaces, dots, slashes - are replaced with underscores, because emitting them literally would produce XML that no parser can read.
Is my data sent to a server?
No. Conversion happens in your browser using its built-in XML parser, so payloads containing customer records never leave your device.
Why does my XML fail to convert?
Usually an unclosed tag, a stray ampersand that should be &, or more than one root element - XML permits exactly one. The error message comes from the browser's own parser, which is strict by design.
Open the JSON ⇄ XML when you are ready. It is free, and you do not need an account.