Modern Niche World MNW

XML to JSON

Paste XML or open a file to get JSON, with attributes as @name, repeated elements as arrays and text as values. Errors show their line and column.

Paste or type XML, or open or drop a file of up to 25 MB. It stays on this page: nothing is sent anywhere or saved.

Element names, separated by commas, exactly as in the XML (prefix included, like media:content).

Paste XML above to see it as JSON.

Everything happens on this page, on your device: your XML is never sent anywhere or saved.

Turn XML into JSON you can use

Older services, feeds and exports often hand you XML, while most code and tools today expect JSON. This page reads XML with your browser’s own XML reader and writes it as JSON by fixed rules, so the same XML always gives the same JSON.

How to use it

  1. Paste or type XML, or open or drop a file of up to 25 MB.
  2. Read the line under the options: what was converted, or the first error with its line and column.
  3. Choose a layout and the options, and name any elements that should always be arrays, such as item in a news feed.
  4. Copy the JSON, or download it as a .json file.

How XML becomes JSON

  • The root element is the top-level key: <library> becomes {"library": …}.
  • An element with only text becomes that text; an empty one becomes "".
  • Attributes come first, as keys starting with @, such as "@id".
  • Text beside attributes or child elements goes in "#text". CDATA counts as text.
  • Elements sharing a name become one array. Names you list under Always make arrays for are arrays even when there’s only one.
  • Comments and processing instructions are left out, and so are the spaces between elements.
  • Namespace prefixes stay in the names, as in "soap:Body".
  • Every value is text, unless you tick the numbers option: then 42 and true become a number and true, while 007 and +5 stay text.

Safe with any file

Browsers don’t fetch DTDs or external entities when they read XML this way, so nothing is fetched. A DOCTYPE that declares entities is refused, because entities can expand a small file into an enormous one (the “billion laughs” attack). The XML is only read, never shown as a web page, so nothing in it can run.

Good to know

  • Order: each array keeps its elements in order, but not where they sat between other elements, and mixed text, as in <p>Hi <b>there</b></p>, loses its place among the children. The tool says when either happens.
  • Big files: a file of several megabytes takes a moment, and the page says it’s working until it’s done.
  • Already have JSON? The JSON Formatter checks and tidies JSON you already have; this page converts XML into it.
  • Next steps: JSON to CSV turns an array of objects into a table, and YAML to JSON converts YAML files.

Frequently asked questions

Why is one element an array and another not?
Elements with the same name under one parent become an array; a name that appears once becomes a single value. If your code expects an array every time, type that name under Always make arrays for, and a single element becomes an array of one.
Can it turn JSON back into XML?
No. XML holds things JSON has no place for, such as comments, mixed text and the order of different elements, so going back means making choices this page doesn’t make. It converts XML to JSON only.
Does it check my XML against a schema or a DTD?
No. It checks that the XML is well-formed: every tag closed and properly nested, attributes in quotes, one root element. It doesn’t validate against XSD or DTD rules, and it never loads a DTD.
Is my XML sent anywhere?
No. Your browser’s own XML reader parses it on your device, and this page’s code converts it. Nothing is sent, logged or saved, so it’s safe for API responses, exports and config files.