Skip to content
My Tiny Utils

Search tools

Type to find a tool, then press Enter to open it.

XML to JSON Converter

Convert XML to JSON and JSON back to XML, with attributes, CDATA, namespaces, and repeated elements handled — and malformed XML reported by line and column.

Processed locally in your browser — nothing is uploaded.

XML to JSON Converter

0 characters

JSON

Output appears here…

About the XML to JSON Converter

Paste an XML document — a SOAP response, an RSS or Atom feed, a sitemap, a Maven pom.xml, an Android layout — and get the same data as JSON. Switch to JSON → XML to go the other way, or press Swap to send the output back through the opposite converter.

XML has things JSON doesn't — attributes, text mixed in with child elements, element order — so every converter has to pick a mapping. This one uses the convention most libraries share, which means the JSON looks like what your code would get from them:

  • Attributes become keys with a prefix: id="1" becomes "@id": 1.
  • Text of an element that is only text becomes its value: <title>Hi</title> becomes "title": "Hi". When the element also has attributes or children, the text goes under "#text".
  • Repeated elements become arrays; a single child stays an object. Set Make arrays to For every child element when your code needs the same shape whether there is one <item> or ten.
  • Numbers and booleans are converted when the text is exactly one — 39.95, true — but 007, 1,000, and integers too big for JavaScript stay strings, so nothing is silently changed.
  • CDATA content is kept verbatim, entities like &amp; and &#169; are decoded, and namespaced names such as soap:Body and xmlns:dc are kept as written.

The prefix, the text key, the array rule, and number conversion are all in Options, and JSON → XML reads the same settings back, so a document survives the round trip.

It doubles as an XML validator. The parser is strict, like the ones that will eventually read your file: a mismatched or unclosed tag, a bare &, an unquoted attribute, a duplicate attribute, or a second root element is reported with the line, the column, and a caret under the exact spot.

Example

Input

<book id="1"><title>Widgets</title><price currency="USD">9.95</price></book>

Output

{
  "book": {
    "@id": 1,
    "title": "Widgets",
    "price": {
      "@currency": "USD",
      "#text": 9.95
    }
  }
}

Common uses

  • Read a SOAP or legacy XML API response in a JavaScript or Python codebase that expects JSON
  • Turn an RSS feed, sitemap, or config file into JSON for a script, a test fixture, or jq
  • Find the exact line where an XML file stops being well-formed
  • Produce an XML payload from JSON for a system that only accepts XML

Limitations

  • Text that is interleaved with child elements (<p>Hello <b>world</b>!</p>) is collected under the text key, so the order of text and elements isn't kept
  • Comments, processing instructions, and the DOCTYPE are dropped from the JSON; the XML declaration is written back only as a standard UTF-8 one
  • No DTD or XSD validation, and only entities declared in the document's own DOCTYPE are known — &nbsp; from an external DTD is reported as unknown
  • An empty JSON array produces no elements, so it can't come back from XML as an empty array

Frequently asked questions

How do I convert XML to JSON?

Paste the XML into the box and the JSON appears below as you type. Attributes become keys prefixed with @, text-only elements become plain values, and repeated elements become arrays. Copy the result or download it as a .json file.

How are XML attributes represented in JSON?

As keys with a prefix — "@" by default — so <price currency="USD">9.95</price> becomes {"@currency": "USD", "#text": 9.95}. You can change the prefix (to "_" or "$", or nothing at all) and the text key in Options, and the JSON → XML direction reads the same settings back.

Why is an element an object in one place and an array in another?

By default an element becomes an array only when it repeats: one <author> is an object, two are an array. That matches most XML libraries, but it means the shape depends on the data. Set "Make arrays" to "For every child element" in Options to get an array every time.

Can I convert JSON back to XML?

Yes. Switch to JSON → XML, or press Swap to send the current JSON across. Keys starting with @ become attributes, "#text" becomes the element's text, arrays repeat the element, and null becomes an empty element. Keys that aren't valid XML names, like "first name", are renamed (first_name) and listed under the output.

Is my XML uploaded to a server?

No. The XML is parsed by a small parser that runs in your browser, so SOAP responses, configs, and feeds with internal data never leave your device.