json

FormatValidateConvert

XML to JSON converter

Result· read-only

—JSON

The result appears here.

Convert

XML to JSON converter.

Your document never leaves the browser.

XML to JSON with attributes as @ keys and repeated elements as arrays — never uploaded.

Paste or drop an XML document and get JSON in the shape most libraries expect, with options for the two things XML cannot tell you.

@

before an attribute’s name, as in "@id"

2

options for what XML cannot say

0

bytes leave your machine

The mapping

The page follows the convention of Newtonsoft.Json, which fast-xml-parser and xml2js users will recognise. The root element becomes a one-key object.

1

The XML

<order id="7">
  <item>pen</item>
  <item>ink</item>
</order>
2

The JSON it gives, at the default settings

{
  "order": {
    "@id": "7",
    "item": [
      "pen",
      "ink"
    ]
  }
}

Mapping

Text or object

An element with only text becomes a string; with attributes or children, an object.

Mapping

Attributes first

Attributes come first, as "@name" keys in source order, then children in the order they first appear.

Mapping

#text

Text beside attributes or children is "#text".

Mapping

Repeats become arrays

A name that repeats among siblings becomes an array in document order; a name that appears once is a single value.

Mapping

Empty and nil

An empty element is "". An element with xsi:nil="true" is null.

Mapping

CDATA and namespaces

CDATA is ordinary text. Namespace prefixes stay in the key, like "soap:Envelope", and xmlns declarations are kept as @ keys.

Two options for what XML cannot say

Always make arrays for: XML cannot tell one <book> from a list of one book, so name the elements that should always be arrays — in the catalog sample, book makes Poetry’s single book an array like the others.

Detect numbers and booleans: XML text has no types, so everything stays a string by default. A code like 007 or a ZIP code like 02134 means what it says only as text. Turn it on and only text that is exactly a JSON number, true or false converts, with the number’s digits kept.

1

An order with one item

<order id="7">
  <item>pen</item>
  <qty>2</qty>
  <zip>02134</zip>
</order>
2

The JSON with Always make arrays for: item, and Detect numbers and booleans on

{
  "order": {
    "@id": "7",
    "item": [
      "pen"
    ],
    "qty": 2,
    "zip": "02134"
  }
}

Refusals and notices

A document that is not well-formed is refused at the first error, with its line and column: mismatched or unclosed tags, a second root, a bare &, an undeclared prefix. So is a DOCTYPE with an internal subset, and an entity other than the five XML predefines, because expanding them is how billion-laughs attacks work. Comments and processing instructions are dropped and counted; mixed content and a change in the order of differently named siblings are noted.

  • mismatched or unclosed tags
  • a second root
  • a bare &
  • an undeclared prefix
  • a DOCTYPE with an internal subset
  • an entity other than the five XML predefines

A bare &

<order id="7">
  <item>pen & ink</item>
</order>

✕ Line 2, column 13: An entity reference must end with a semicolon.

Private by construction

The conversion runs in your browser, in the same engine the editor uses. The document is never uploaded, never logged and never leaves your machine — there is no server to send it to. Once the page has loaded it keeps working with the connection off.

Going the other way?

FAQ

Frequently asked questions

Didn’t find your answer?Write to us on the contact page →
Is an external DTD fetched?

Never. A DOCTYPE without an internal subset is ignored and noted; the page makes no network request.

Why is one element an object and its sibling an array?

Because it appears once. Name it under Always make arrays for and it is an array wherever it appears.

Which encodings are read?

UTF-8 and UTF-16. A file declaring another encoding is refused, with a sentence asking for it to be saved as UTF-8.

Keyboard shortcuts

Send feedback

Questions, bug reports and feature requests are all welcome. A bug report is easiest to act on with the shape of the document that caused it — never send anything confidential.

Email us

Contact page, in a new tab, so this page stays as it is.

Settings

Indent

The result is written with it — YAML and XML at 2 spaces when it is Tab.

Code text size
14 px

Both panes.

Wrap long lines

Load from a URL

Your browser fetches it directly — the request goes to that site, never to us.