Free tool
XML to JSON, and back.
Paste a SOAP response, a feed, a config file or a legacy export and get JSON your code can use. Attributes become @keys, repeated elements become arrays — or always arrays, so one-item records don’t break your loop — and malformed XML comes back with the parser’s error.
Paste XML above to convert it.
Publishes the JSON and its source side by side on Comma: one URL for the payload under discussion, comments anchored to the exact field, every re-publish kept as a revision. Free, no card.
The conversion rules
- Attributes become
@namekeys:<total currency="USD">→"@currency": "USD". - Text next to attributes or children goes under
#text; an element with only text collapses to the text itself. - Repeated elements become an array. With “Always use arrays” every child element is an array, so a record with one
<item>has the same shape as one with five. - Types are inferred only where safe:
184.50→184.5,true→true, but00417stays a string. - CDATA is read as text; comments and the
<?xml?>declaration are dropped.
When the payload should be a link
A 400-line SOAP response pasted into a ticket loses its indentation and nobody can point at the field that is wrong. Published to Comma it keeps its shape, reviewers comment on the exact line, and the corrected payload lands as a revision you can diff. Test results in JUnit XML are better still as a rendered report — what JUnit XML is and how to publish one.
Questions
- How do I convert XML to JSON?
- Paste the XML into the editor on this page or drop an .xml file onto it. The JSON appears as you type; copy it or download a .json file. It runs in your browser with the same XML parser the browser uses for web pages, so anything well-formed converts and anything malformed comes back with the parser's error and line number.
- How are XML attributes converted?
- Attributes become keys prefixed with @, so <total currency="USD">184.50</total> becomes {"@currency": "USD", "#text": "184.50"}. Text that sits next to attributes or child elements goes under #text; an element with only text collapses to that text. This is the convention most XML libraries use, and the JSON → XML direction reads it back.
- Why is one element an object and another an array?
- XML doesn't say whether an element can repeat, so a converter only sees it repeat when it does: two <item> elements become an array, one becomes a single object. Code that loops over the result then breaks on the record with one item. Turn on “Always use arrays” and every child element is an array, even when it appears once — predictable shape, slightly noisier JSON.
- What happens to namespaces like ext:gift?
- By default the prefix is kept, so the key is ext:gift and xmlns declarations appear as @xmlns:ext attributes. “Strip namespaces” uses local names instead (gift) and drops the xmlns attributes — easier to read and to address in code, as long as two namespaces don't use the same local name in one element.
- Are numbers and booleans converted?
- XML has no types — every value is text. With “Infer types” on, values that are plainly numbers or true/false become JSON numbers and booleans, while codes with leading zeros (00417) and integers too long for JavaScript stay strings. Turn it off to keep every value exactly as written.
- Can I convert JSON to XML?
- Yes — click JSON → XML or Swap. Keys starting with @ become attributes, #text becomes the element's text, arrays become repeated elements, and keys that aren't legal XML names (“first name”, “1st”) are rewritten. If the JSON doesn't have exactly one top-level key, it is wrapped in a <root> element, because XML needs a single root.
- What about comments, CDATA and the XML declaration?
- CDATA sections are read as ordinary text, so markup inside them is preserved as a string. Comments, processing instructions and the <?xml?> declaration are dropped — JSON has no place for them.
- Is my XML uploaded anywhere?
- No. Parsing and conversion happen in your browser. The data only leaves your machine if you click “Get a shareable link” and publish it.
Related: YAML to JSON · JSON formatter · JSON to CSV · JSON to HTML table · HTML escape · all free tools