JSON ⇄ XML
Converts between JSON and XML with configurable handling of attributes, arrays and text nodes.
Converts XML into JSON and back. There is no canonical mapping between the two — XML has attributes, ordered mixed content and namespaces, JSON has none of those — so this page makes its choices explicit and lets you change them rather than hiding a convention.
`@id` for an attribute.
Where an element’s own text goes.
XML
JSON
@name keys, an element’s own text becomes #text, and repeated siblings become an array. The last of those is where the round trip can lose information — a list that happens to have one element comes back as a single object unless “always use arrays” is on.In
215 chars
Out
399 chars
How to use it
Pick the direction
The two sides keep separate inputs, so switching back and forth does not lose what you had pasted.
Set the attribute prefix and text key
`@` and `#text` are the widespread convention (fast-xml-parser, xml2js and others use them), but if the JSON you have to produce uses something else, change them here rather than post-processing.
Turn on always-use-arrays if the JSON is going to code
This is the lossy part of the mapping: one `<item>` becomes an object, two become an array, and consuming code has to handle both. Forcing arrays makes the shape stable at the cost of some verbosity.
Common questions
Does the round trip give me my XML back?
Structurally usually, byte for byte no. Comments, processing instructions and the distinction between `<a/>` and `<a></a>` do not survive, and mixed content — text and elements interleaved — cannot be represented in JSON in a way that preserves the order.
Why is `12` a string?
Because XML has no types — every value in a document is text, and only a schema says otherwise. The Coerce toggle will guess numbers and booleans, but it is a guess: a product code of `0123` becomes 123, and a version string of `1.10` becomes 1.1.
What happens to namespaces?
Prefixes are kept as part of the element name — `soap:Body` becomes the key `soap:Body` — and `xmlns` declarations come through as ordinary attributes. Nothing is resolved to a namespace URI, so two documents using different prefixes for the same namespace produce different JSON.
Can I feed it a SOAP response?
Yes, and that is one of the common reasons to be here. The envelope, the body and the payload all come through as nested objects; the `@` keys are where the SOAP attributes end up.
Feed it from
XML Formatter & Validator
Indents XML and reports the line and column of the first well-formedness fault.
XPath Tester
Evaluates an XPath or CSS selector against XML or HTML and lists every matched node.
JSON Formatter & Validator
Pretty-prints, minifies and validates JSON, pointing at the exact line and column of a syntax error.
YAML Formatter & Validator
Re-indents YAML consistently, validates it, and flags the tab and anchor mistakes that break parsers.
Next
These accept what this tool produces, so the result can go straight in.
JSON Formatter & Validator
Pretty-prints, minifies and validates JSON, pointing at the exact line and column of a syntax error.
JSONPath Tester
Runs a JSONPath expression against a document and highlights the matched nodes as you type.
XML Formatter & Validator
Indents XML and reports the line and column of the first well-formedness fault.
XPath Tester
Evaluates an XPath or CSS selector against XML or HTML and lists every matched node.
Base64 Encoder & Decoder
Encodes and decodes Base64 and Base64URL for text or files, handling UTF-8 correctly.
curl to Code
Converts a curl command into fetch, axios, Python requests, Go, PHP or PowerShell.