Skip to content
ZeroServer.tools

XML to JSON

Convert XML markup into a structured JSON object.

or drop a file here
JSON Output

Converted to 18 lines of JSON.

Converting XML to JSON

This converter parses your XML into a tree and maps each element to a JSON property, turning repeated sibling tags into arrays and coercing numeric and boolean text into real JSON types. Leaf elements become string, number, or boolean values. Conversion is lossless: attributes are preserved as @name properties, and an element carrying both attributes and text keeps its text under #text — the badgerfish convention, so the result stays round-trippable. Two switches control the shape: Keep values as strings turns off type coercion (so 01234 stays a zip code, not the number 1234), and Always use arraysmakes every child element a list so consumers never have to special-case "one item versus many". Parsing runs entirely in your browser with a lightweight tokenizer.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Turning a SOAP or RSS response into JSON for a modern client.
  • Making a verbose XML document easier to read and query.
  • Producing a JSON fixture from an XML source.
  • Comparing two XML documents by converting both and diffing the JSON.
  • Migrating data out of an XML pipeline that a newer service will consume.

Frequently Asked Questions

Why is there no single correct XML to JSON mapping?
Because XML has attributes, namespaces, ordering and mixed content, and JSON has none of them. Every converter invents a convention — usually an `@` prefix for attributes and `#text` for content — and none is standard, which is why two converters disagree on the same file.
How is a single repeated element handled?
This is the classic ambiguity. One `<item>` looks like an object and two look like an array, so the same schema produces different JSON shapes depending on the data. Robust converters take a list of element names that should always be arrays.
What happens to namespaces?
Usually stripped, because a prefixed key is awkward in JSON and the prefix is not the identity anyway — the namespace URI is. Stripping collides two different elements that share a local name, which is a silent data merge rather than an error.
Are values typed?
Only by guessing, since XML has no types without a schema. A converter that infers turns `007` into 7 and `1.10` into 1.1; one that does not leaves everything a string. Neither is right in general, which is why the setting matters more than it looks.
Can the conversion be reversed?
Only if the convention is known and the original had no mixed content, no comments and no meaningful ordering. In practice XML to JSON is a one-way trip, which is why it suits consuming a feed rather than storing it.

Common errors and gotchas

  • Losing the attribute-versus-element distinction, which JSON has no natural way to express.
  • Producing a single object where a list was intended, since one repeated element looks like one child.
  • Dropping mixed content, where text and elements are interleaved and JSON cannot hold both cleanly.
  • Ignoring namespaces, which either disappear or become awkward prefixed keys.
  • Assuming types appear, when XML text content is text and any coercion is a guess.

Related Converters tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate