Skip to content

XML to JSON, CSV and Excel converter

Convert XML to JSON, or XML to CSV and Excel with each repeating element as a row, and JSON back to XML. Your files are never uploaded.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up

Paste or open XML to turn it into JSON. Nothing you add leaves this page.

How it works

XML is read with the same parser as the XML formatter, which follows the XML 1.0 standard with namespaces, in a background worker inside this tab. It never downloads a DTD a file points to and never expands entities a DOCTYPE declares, which is how a few lines of XML can grow into gigabytes; such references stay as written, like &company;, and the page says so. References like & and © become the characters they stand for, and CDATA sections become plain text.

XML has no single JSON form, so the page follows one well-known convention, Python's xmltodict, and its tests check the result against xmltodict itself on over 400 documents. Text is trimmed of spaces at either end. Comments and processing instructions are left out, because JSON has no place for them, and the page counts them. Two things XML can say and this JSON can't are named when they happen: text sitting between child elements is joined into one #text, and elements of different names mixed together lose their order between names.

For CSV and Excel, every element on the chosen path becomes a row, wherever it sits. Attributes become columns named with @, child elements columns named after them, and deeper ones are joined with dots (address.city). An element's own text goes in the column with its name, so a <price currency="EUR"> gives price and price.@currency. An element that repeats in any row is numbered in every row, so the columns line up. The CSV follows RFC 4180 and the Excel file is written by the same code as the JSON to CSV converter, with cells that look like formulas counted and, if you like, defused.

JSON to XML reads strict JSON, writes the XML indented with 2 spaces, and checks it with the XML parser before showing it. Your XML and JSON are never uploaded, saved or put in the page address. Big formatter sites have leaked what people pasted into them; this page has no server to send it to.

Questions

How do I convert XML to JSON?

Paste the XML into the box or open an .xml file. The JSON appears as you type, indented with 2 spaces, ready to copy or download as a .json file. If the XML isn't well-formed, the page says what is wrong and on which line and column instead.

How are attributes, text and repeated elements written in the JSON?

The way Python's xmltodict writes them, which many programs expect. Each element becomes a key. An element with only text becomes that text; one with attributes or child elements becomes an object, with attributes as keys starting with @ (like @id) and its text as #text. An element that appears more than once in the same parent becomes an array, and an empty element becomes null. Values stay text unless you tick “Numbers and true/false as values”, and namespace prefixes are kept as written.

How do I convert XML to Excel or CSV?

Choose XML to CSV. The page picks the element that repeats, like each <order> in an orders file, and makes one row of each; attributes and child elements become columns, and repeats inside a row get a column each (item.1, item.2). Pick other rows under “Rows from”. Download a .csv, or a .xlsx where numbers and dates are real Excel values and codes with leading zeros stay text. Anything outside the rows is listed, so nothing goes missing without you knowing.

How do I convert JSON to XML?

Choose JSON to XML and paste the JSON. Keys become elements, keys starting with @ become attributes, #text becomes the element's text, and arrays become the element repeated. XML needs one root element, so JSON without exactly one top-level key is put inside <root>, and keys that can't be XML names, like ones with spaces, are changed and listed.

Limits

The limit is 10,000,000 characters (about 10 MB) either way. The table shows the first 100 rows and 50 columns; the CSV and Excel files have them all, up to Excel's 1,048,576 rows and 16,384 columns. Very wide data can keep each list in one cell as JSON text instead.

It doesn't validate against an XSD schema or DTD, run XSLT, or follow XInclude. Spaces at the ends of text are trimmed, even under xml:space="preserve". Going from XML to JSON and back gives the same data, but not the same file: comments, the order of differently named elements and where text sat between elements aren't kept. Reloading the page clears everything.

Privacy

This tool runs entirely in your browser. The files you open and what you type are never sent to a server, and nothing is stored after you close the page. See the privacy page.

Related tools