onlinetools.dev

XML ↔ JSON Converter

Convert XML documents to JSON and back, attributes included

Runs locally
loading…
About this tool

Convert XML to JSON to feed legacy SOAP responses, RSS feeds or Maven POMs into JavaScript, jq or a JSON-native API — or go the other way and produce XML from JSON data. Attributes are kept: they become "@_name" keys, and text content that coexists with attributes lands under "#text", so no information silently disappears.

The two formats disagree on fundamentals, and this converter makes the standard pragmatic choices: repeated sibling elements collapse into a JSON array, numeric-looking values become numbers, and namespaces travel as part of the element name. Round-tripping XML → JSON → XML preserves structure and content for typical documents.

Both directions run locally in your browser. Paste an invoice feed or an API response without it going anywhere.

Frequently asked questions

Why do some values come back as numbers instead of strings?
The parser recognizes numeric text and converts it, which is what most consumers want. Beware of identifiers with leading zeros (product codes, phone numbers) — if that matters for your data, quote them post-conversion or treat the output as a starting point.
How are repeated elements handled?
Two or more siblings with the same name become a JSON array under that key. A single occurrence stays a plain object — that asymmetry is inherent to the mapping, so code consuming the JSON should tolerate both shapes or normalize first.
What do the @_ and #text keys mean?
@_ marks what was an XML attribute, #text carries element text when attributes are also present. Feeding the same convention back into the JSON → XML direction reconstructs the original markup.
Why does JSON → XML reject my top-level array?
An XML document must have exactly one root element, and a bare array has none. Wrap the array in an object — {"items": {"item": [...]}} — and the converter produces a well-formed document.
Related tools