Skip to content
cliplimeClipLime

Convert XML to JSON

Paste XML or drop a file and get JSON, with attributes, repeated elements and numbers handled in the open.

Runs on your device, nothing is uploaded

Convert from

to

Paste, type, drop a file here or load one.

0 characters, 0 lines

Options

XML holds only text. Each value that is a clean number becomes a number, one by one. All types also reads true/false, and empty elements and the words null and NULL become null.

XML attributes

How attributes are named next to child elements.

Indentation

More options

ns:name becomes name.

At a glance

Input
XML text or an .xml file: SOAP messages, RSS and Atom feeds, sitemaps and exports from other software. The encoding is detected from the file's bytes (UTF-8, UTF-16 or Windows-1252), not from the XML declaration.
Attributes
Each attribute becomes a key that starts with @, such as @id, listed before the child elements. You can choose plain names instead.
Repeated tags
Elements that repeat become a JSON list. An element that appears only once stays a single value.
Values
Numbers, true and false, empty elements and the words null and NULL are detected one value at a time, or you can keep everything as text.
Namespaces
Prefixes such as soap: are kept by default. A switch under More options removes them, together with the xmlns declarations.
Errors
Broken XML is shown with its line and column and a plain explanation, such as a tag that is never closed or a bare & in text.
Privacy
Your XML is converted in your browser tab and never uploaded. Free, with no sign-up.

How to do it

  1. 1

    Add your XML

    Paste it, drop a file on the input box, or press Load a file. Example fills in a small team file with attributes and a repeated element.

  2. 2

    Choose how it is read

    Under Options, decide whether numbers and true and false become JSON values or stay text, and whether attributes keep the @ in front of their names.

  3. 3

    Read the result

    The JSON appears as you type. If the XML is not well formed, the line and column are shown. The notes under the result say what was assumed.

  4. 4

    Copy or download

    Press Copy, or Download for a .json file. The indentation can be 2 or 4 spaces, a tab, or none at all.

How XML elements, attributes and text map to JSON

XML and JSON both nest data, but XML has things JSON does not: attributes, text mixed in with tags, and no difference between one item and a list of one. The converter follows fixed rules, so the result is predictable.

  • Elements become keys. The document element is the single key at the top, so <team> becomes {"team": {...}}.
  • Attributes become keys that start with @ and come before the child elements. <member id="1" role="design"> gives "@id": 1 and "@role": "design".
  • Text next to attributes is kept under #text. <price currency="EUR">12.50</price> becomes {"price": {"@currency": "EUR", "#text": 12.5}}.
  • Empty elements such as <zip/> become null when all types are detected, and an empty string otherwise.
  • Comments, processing instructions, the XML declaration and the DOCTYPE are dropped. CDATA sections become ordinary text.

Character references are decoded, so &amp; becomes & and &#233; becomes é. Text is trimmed of spaces and line breaks at both ends. Blank lines before the first tag, also in front of the <?xml ?> line, are allowed, and element names such as constructor or toString are kept as they are. A document needs one root element: a second element after the first, even a self-closing one such as <b/>, is reported with its line and column.

The one item list problem, and what else XML cannot say

A JSON list is explicit. XML has no list type: a list is the same tag written several times. So <skill>Figma</skill><skill>Illustration</skill> becomes "skill": ["Figma", "Illustration"], but a member with a single <skill> gives "skill": "TypeScript", a plain string. Code that expects a list will break on the single case, so check with Array.isArray or wrap the value in a list yourself before looping.

Two more things are not kept. The converter cannot warn about them, because the XML is perfectly valid:

  • Order between different tags. <a>1</a><b>2</b><a>3</a> becomes "a": [1, 3], "b": 2, because all the a elements are gathered under one key.
  • Text mixed with tags. In <p>Hello <b>bold</b> world</p> the loose text is merged into one #text value, with the pieces trimmed and joined, giving Helloworld. XML that is really a document, such as XHTML, does not fit a data format like JSON.

Numbers, true and false, and attribute names

XML stores only text, so the converter has to decide which values are numbers. It looks at each value on its own, and only clean numbers are converted: digits with an optional minus sign and decimal point, no leading zeros and at most 15 digits.

  • 12.50 becomes 12.5, and version="1.0" becomes 1. Set Values to Keep as text if you need 1.0 exactly as written.
  • 007, +1 555 0100, 1e3 and a 20 digit ID stay text.
  • true and false become booleans, and an empty element and the exact words null and NULL become null, but only with Detect all types. To keep the word null as text, choose Detect numbers or Keep as text.

If an attribute and a child element share a name, as in <item id="1"><id>child</id></item>, plain attribute names would collide. The attribute then keeps its @ and a warning says so.

Namespaces, SOAP messages and feeds

Names with a prefix, such as soap:Body or xhtml:link, keep the prefix by default, and the xmlns declarations show up as keys like "@xmlns:soap". That keeps the namespace information but makes the keys awkward to use. Turn on Remove namespace prefixes under More options to get Body and link and to drop the declarations. If two names differ only by their prefix, they end up under the same key, so check the result when a document mixes namespaces.

RSS and Atom feeds convert with their structure intact: rss, then channel, then a list of item objects. If you want one row per item for a spreadsheet, use XML to CSV instead.

Questions people ask

How are XML attributes written in JSON?

As keys that start with @, such as "@id": 1, placed before the child elements. If an element has attributes and text, the text is kept under "#text". You can choose plain names under XML attributes, and the converter warns if an attribute and an element would then have the same name.

Why is one element an object and repeated ones a list?

XML has no list type, so the converter can only see how often a tag appears. Two or more become a list and one stays a single value. If your code needs a list every time, wrap single values in a list after converting, or check with Array.isArray.

Why did 1.0 become 1, and how do I keep it as written?

With number detection on, a clean number is written in its shortest form, so 1.0 becomes 1 and 12.50 becomes 12.5. Set Values to Keep as text and every value, attributes included, stays exactly as written.

Does it work for SOAP, RSS and sitemap files?

Yes, the structure is kept as it is. SOAP messages are easier to read with Remove namespace prefixes switched on. For one row per record, for example per RSS item or sitemap URL, use the XML to CSV page.

Why do I get an error about the character &?

In XML text a bare & starts a character reference, so it has to be written as &amp;. The same goes for < in text, which has to be &lt;. The error shows the line and column of the first one it found.

Is my XML uploaded?

No. The text or file is read and converted in your browser tab, so private data such as invoices or API responses stays on your device.