Skip to content

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.

🔒 Runs entirely in your browserjsonxmlconvert
Direction

`@id` for an attribute.

Where an element’s own text goes.

XML

JSON

There is no canonical mapping between XML and JSON, so this one is explicit about its choices: attributes become @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

  1. Pick the direction

    The two sides keep separate inputs, so switching back and forth does not lose what you had pasted.

  2. 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.

  3. 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

Next

These accept what this tool produces, so the result can go straight in.