Skip to content
Toolbench

XML to JSON Converter

New

Convert XML to JSON with the array question answered out loud rather than guessed at.

Runs entirely in your browser

Loading tool...

How to use

  1. Paste your XML — a document, an RSS feed, a SOAP response, or a fragment from the middle of one.
  2. Choose how repeated tags come out: an array only when a tag repeats, or always an array.
  3. Decide whether to keep attributes, and whether numbers should stay as text.
  4. Copy the JSON, or download it as a file.

Features

  • Answers the question every XML converter has to answer: one item element and two of them are the same schema, so "always an array" gives you a shape that does not change with the sample.
  • Attributes are prefixed, so an attribute and a child element sharing a name never collide.
  • Numbers stay text unless you ask otherwise, because coercion quietly destroys leading-zero part numbers and IDs too long for a float.
  • Mixed content keeps both halves — the text and the elements sitting inside it.
  • Syntax errors come from the same parser as the XML formatter, so you get the line and the tag rather than "invalid input".

Frequently asked questions

Why does the same tag become an object in one file and an array in another?
Because XML has no arrays. A list of one and a list of two look different in the document even though the schema says both are lists, and nothing in the file itself can tell the converter which was meant. "Array when repeated" gives the compact result people expect from a sample; "always an array" gives a shape that stays the same when a second element arrives, which is what you want if code is going to read the JSON.
What happens to attributes?
They become ordinary keys with a prefix, @ by default, so an attribute called id and a child element called id can both exist without one overwriting the other. Turn them off if you only want the element content, and change the prefix if @ is awkward for whatever reads the JSON next.
Why are my numbers strings?
Because in XML they are strings — the document has no types. Reading them as numbers is off by default because it is lossy in ways you only notice later: a part number written 007 becomes 7, an ID longer than 15 digits gets rounded by the nearest float, and a version like 1.0 loses its zero. Switch it on when you know the data is safe.
What happens to comments and the XML declaration?
They are dropped, because JSON has nowhere to put them, and the tool counts them and tells you rather than letting them disappear silently. CDATA is different: its content is real data, so it is kept and read as ordinary text.

Indents XML without editing it: mixed content keeps its spacing, and a tag that does not match is named with the line it is on.

Format and beautify JSON instantly.

Turn a JSON array into a spreadsheet, with columns taken from every record.

Convert CSV or TSV into JSON, handling quoted fields the way a spreadsheet exports them.

XML to JSON Converter — Convert XML Online, Free