Shard Tools

XML to JSON

Convert XML to readable JSON in your browser.

Maintained by Roshan.

Use XML to JSON

Converts between XML and JSON in this tab using the browser's own XML parser. Nothing is uploaded, which matters for the configuration files and invoices these formats usually carry.

How the two shapes are mappedAttributes become keys prefixed with @, mixed text sits under #text, and repeated sibling tags collapse into an array. Values stay strings: turning 0123 into a number would quietly break postcodes and version numbers.

Explore developer and data tools

Find related browser-local tools for nearby tasks without starting another search.

Browse all developer and data tools

About XML to JSON

XML and JSON do not describe data the same way, so every converter between them has to invent a convention, and no two libraries invent quite the same one. XML has attributes; JSON has no equivalent. XML allows text and child elements side by side in one node; JSON objects cannot hold a bare string alongside named keys. XML makes no distinction between one element and a list of one, while JSON draws a hard line between a value and an array. Rather than leaving you to reverse-engineer the mapping from the output, the rules used here are stated plainly, and they are chosen to survive a round trip. The whole conversion runs in this tab, which is worth noting given that the XML people actually need to convert tends to be configuration, invoices and API payloads.

Work through the input

  1. The document is parsed by the browser's own XML parser. That is deliberate for safety: browser XML parsing does not resolve external entities, so the classic entity-expansion attack that reads local files has nowhere to go.
  2. Malformed input is caught properly. Browsers report a parse failure as a parsererror element rather than by throwing, so an unchecked converter happily returns JSON describing the error message instead of your data.
  3. Attributes become keys prefixed with @, which keeps them distinguishable from child elements that happen to share a name.
  4. An element containing only text becomes that string directly. When it has attributes as well, the text moves to a #text key so nothing has to be discarded.
  5. Repeated sibling elements with the same name collapse into an array, and namespace prefixes are preserved verbatim so soap:Body stays soap:Body.

When xml to json is useful

A SOAP response you need to inspect

Converting to JSON makes a deeply nested envelope far easier to read. Namespace prefixes are preserved, so you can still tell which part of the document each element came from.

An RSS or sitemap file

Both are XML with heavy repetition, which converts cleanly into arrays. A feed with one item produces a single object rather than an array, so guard for that in code.

Check the output

Questions about XML to JSON

How are attributes represented?

As keys prefixed with @. An element written as <price currency="GBP">42.50</price> becomes an object with an @currency key and the value under #text.

Why are all my numbers strings?

Because XML carries no type information, so any conversion would be a guess. Guessing is how converters silently break postcodes, phone numbers and version strings.

What happens if my XML is invalid?

You get an error with the parser's own explanation. The tool checks for the browser's parsererror element rather than assuming a parse succeeded.

Is a single repeated element an array?

No. With only one occurrence there is nothing in the document indicating a list, so it becomes a plain value. This is the main thing to allow for when consuming the output.

Is my XML sent to a server?

No. The browser's built-in parser does the work in this tab, and no request carries the document anywhere.

Related tools

JSON to XML

Turn JSON into well-formed XML in your browser, with escaping and element naming handled correctly.

JSON Formatter and Validator

Format, minify, and validate JSON locally in your browser. Inspect keys, values, nesting depth, and root type without sending private API data to a server.

YAML to JSON Converter

Convert YAML to JSON or JSON to YAML in your browser. Handles multi-document files, follows YAML 1.2, and uploads nothing.

INI to JSON

Turn an INI configuration file into JSON in your browser. Sections become nested objects and values stay strings.

Query String to JSON

Turn a URL query string into readable JSON in your browser. Repeated keys become arrays rather than being lost.