XML to JSON

Convert XML to clean, pretty-printed JSON in your browser - with control over attributes and value types. Nothing is uploaded.

Attributes become keys prefixed with @_, so id="7" maps to @_id.

Turn XML into usable JSON

Plenty of legacy APIs, RSS feeds and configuration files still speak XML, but most modern code would rather work with JSON. Paste your XML above and it is converted the moment you stop typing, using a proper XML parser rather than a fragile regular expression. The result is pretty-printed JSON you can copy straight into your editor or download as a file.

Attributes and the @_ prefix

XML draws a line between an element attribute and a child element, but JSON does not. To keep the two apart, attributes are converted to keys prefixed with @_. So <user id="7"> gives you "@_id" alongside any child elements, and nothing collides. If you only care about the element content, untick Preserve attributes and those keys disappear entirely.

Types and validation

By default, values that look like numbers or booleans are converted to real JSON numbers and booleans, in both text and attributes. Switch Parse numbers and booleans off when you need everything to stay a string - useful for identifiers with leading zeros. Before any conversion happens the document is validated, so malformed XML gives you a line-numbered error instead of broken output.

Need the other direction or a tidy-up? Use the JSON to YAML converter, pretty-print with the JSON formatter, or reshape tabular data with JSON to CSV.

Frequently asked questions

How are XML attributes handled?
With "Preserve attributes" ticked, each attribute becomes a JSON key prefixed with @_ so it never clashes with a child element of the same name. For example id="7" becomes "@_id". Untick the option to drop attributes entirely and keep only element content.
Why the @_ prefix on some keys?
XML lets an element have both an attribute and a child element with the same name. JSON has no such distinction, so attributes are prefixed with @_ to keep them separate and predictable. It is a widely used convention from the fast-xml-parser library.
What does "Parse numbers and booleans" do?
With it on, a value like 42 becomes a JSON number and true or false becomes a JSON boolean, in both text content and attributes. Turn it off to keep every value as a string, which is safer for things like zip codes or IDs with leading zeros.
What happens if the XML is invalid?
The document is validated before conversion. If a tag is unclosed or mismatched you get a clear message with the line and column of the problem, and no partial or misleading JSON is produced.
Is my XML sent to a server?
No. Parsing and conversion run entirely in your browser with JavaScript. Nothing you paste is uploaded, so it is safe for private feeds and payloads.