Data · Free tool

XML to JSON Converter

Convert XML to JSON online with exact error lines. Keep attributes, detect numbers, force arrays, strip namespaces and handle CDATA, then download .json.

Instant resultsPrivate by defaultNo sign-up
Attribute prefix
Indent
More options Start element, arrays, key case, namespaces, comments
Arrays
Key case
Empty elements
Shortcuts: Ctrl/⌘ + S downloads, Ctrl/⌘ + Shift + C copies the result.
XML inputValid XML
485 B · 17 linesDrop a file · up to 10 MB
Valid JSON564 B · 29 linesUpdates live
15XML elements
4Attributes
4Nesting depth
+16%Size change

Converts as you type. Your XML never leaves this browser.

About this tool

A free online XML to JSON converter that parses XML safely in your browser and turns it into clean, readable JSON as you type. Paste XML, or open or drop an .xml, RSS, Atom, SOAP or config file. Repeated elements become arrays, attributes are kept with an @ prefix, element text sits under #text when an element also has attributes or children, and numbers and booleans are detected without stripping leading zeros. Force chosen elements to always be arrays, strip namespace prefixes, ignore attributes, keep comments and CDATA, and pick how empty elements are written. Malformed XML is reported with the exact line, column and reason, such as a mismatched closing tag or an unescaped ampersand. Nothing is uploaded, and DTD entities are never expanded.

Features

Live conversion

JSON updates as you type or paste, and long documents convert without freezing the editor.

Precise XML errors

Mismatched or missing closing tags, unquoted attributes, duplicate attributes, unescaped & and < characters and multiple roots are reported with line and column, and underlined in the editor.

Attributes with a prefix

Attributes become keys such as "@id". Switch to -, _, $ or no prefix, or ignore attributes altogether.

Automatic and forced arrays

Repeated elements become arrays automatically. List element names that must always be arrays, or make every element an array, so your code always sees the same shape.

Number and boolean detection

Text such as 44.95, -3 and true becomes a JSON number or boolean, while ZIP codes and IDs with leading zeros such as 00123 stay strings. Turn detection off to keep everything as text.

Namespaces and SOAP

Keep prefixes such as soap:Body, or strip them and drop xmlns declarations for simpler keys. xsi:nil="true" becomes null.

Text, CDATA and comments

Mixed text goes under #text, CDATA can be merged into text or kept under #cdata, and comments can be kept under #comment.

Empty elements your way

Write <empty/> as null, an empty string or an empty object.

Round-trip friendly

Uses the same @ and #text conventions as the JSON to XML converter, and reads its type attributes to restore numbers, booleans, nulls and arrays.

SOAP body extraction

When the input is a SOAP envelope, one click converts only the message inside Body. Start at element converts any part of a document, such as one RSS channel.

camelCase or snake_case keys

Rename keys as you convert: OrderID becomes orderId or order_id, and soap:Body becomes soapBody, ready for JavaScript or Python code.

Tree view

Browse the converted JSON as a collapsible tree and copy the JSONPath of any value, such as $.catalog.book[1].price.

Types from XML

Generate TypeScript interfaces, Zod schemas, Go structs, Python dataclasses or Pydantic models, Java, Kotlin or Rust types from the converted JSON.

XSD generator

Infer an XML Schema (XSD) from the XML input, with element and attribute types, optional and repeated elements, and nillable values.

Safe parsing

Custom DTD entities are never expanded, which prevents billion-laughs and external-entity attacks, and nothing is fetched from the network.

Private by design

XML is converted in your browser and is never uploaded. Option choices are remembered on this device only.

How XML maps to JSON

Each XML element becomes a JSON key named after the element. An element that contains only text becomes a string, or a number or boolean when detection is on. An element with attributes or child elements becomes an object: attributes are written with the attribute prefix, children become keys, and any text goes under #text.

When the same element name appears more than once inside a parent, the values are collected into an array in document order. The root element becomes the single top-level key unless you turn off Keep root.

<catalog>
  <book id="1"><title>XML</title><price>39.95</price></book>
  <book id="2"><title>JSON</title></book>
</catalog>

{"catalog":{"book":[
  {"@id":1,"title":"XML","price":39.95},
  {"@id":2,"title":"JSON"}
]}}
Repeated <book> elements become an array, attributes get an @ prefix and the price becomes a number.

Why a list sometimes is not an array

XML does not mark lists, so a converter can only infer them from repeated names. A feed with two <item> elements produces an array, but the same feed with one <item> produces a single object. Code that loops over the result then breaks on small inputs.

Add those element names to Always-array elements (for example item, book) so they are arrays even when they appear once, or choose Arrays: Always to make every element an array.

Namespaces, SOAP and xsi:nil

Namespaced XML such as SOAP envelopes uses prefixes like soap:Envelope and m:Price. By default the prefixes are kept in the JSON keys, together with xmlns declarations as attributes, so no information is lost. Turn on Strip namespaces to get shorter keys such as Envelope and Price; elements from different namespaces with the same local name then share a key.

An element marked xsi:nil="true" is written as null, matching how XML Schema represents a missing value.

Fixing common XML errors

XML must be well-formed before it can be converted. The converter stops at the first problem, explains it and highlights the position. The most common causes are listed below.

  • Closing tag does not match: every <tag> needs a matching </tag> in the right order, and names are case-sensitive.
  • Unescaped '&': write & as &amp; in text and attribute values, for example AT&amp;T.
  • '<' in an attribute value: write it as &lt;.
  • Attribute value must be in quotes: use id="1" or id='1', never id=1.
  • Only one root element: wrap several top-level elements in a single parent.
  • Text before the root element: remove stray characters or a byte-order mark copied before <?xml.

How to use it

  1. Paste XML into the left editor, drop or open an .xml file, or select Sample for a book catalog, an RSS feed or a SOAP response.
  2. Choose the attribute prefix and indentation, and whether to detect numbers and booleans and keep the root element. Open More options to force arrays, strip namespaces, ignore attributes, keep comments or CDATA, and set empty-element values.
  3. Copy, download or share the JSON, or switch the output to Tree, Types or XSD. If the XML has an error, read the message and select Go to line to jump to it.

Common uses

  • Read SOAP, RSS, Atom and other XML API responses as JSON in JavaScript or Python code
  • Migrate XML configuration, exports and data feeds into JSON-based apps and databases
  • Validate XML for well-formedness and find the exact line of a syntax error

Common questions

How do I convert XML to JSON?

Paste or open your XML in the left editor. The JSON appears on the right as you type. Adjust the options if needed, then copy the JSON or download converted.json.

How are XML attributes converted?

Each attribute becomes a key with the attribute prefix, @ by default, so <book id="7"> gives {"@id": 7}. You can use -, _, $ or no prefix, or turn on Ignore attributes to drop them.

Why is a single element not converted to an array?

XML has no array type, so arrays are created only for names that repeat. Add the element name to Always-array elements, or set Arrays to Always, to get an array even when there is one element.

Are numbers and booleans converted?

With Detect numbers & booleans on, values like 12, 4.5, -3, true and false become JSON numbers and booleans. Values with leading zeros, such as postal codes and IDs, stay strings. Turn the option off to keep every value as a string.

What happens to text that sits next to child elements?

It is stored under the text key, #text by default. JSON objects cannot record where text appeared between child elements, so that position is not kept; the converter notes when this happens.

How are namespaces handled?

Prefixes such as soap:Body are kept in the keys and xmlns declarations become attributes. Turn on Strip namespaces to remove prefixes and xmlns attributes.

Does it support CDATA and comments?

Yes. CDATA content is merged into the element text by default, or kept separately under #cdata. Comments are skipped unless you turn on Keep comments, which stores them under #comment.

Can it check whether my XML is valid?

It checks that the XML is well-formed and shows the line, column and reason for the first error. It does not validate against an XSD or DTD schema.

How do I convert a SOAP response to JSON?

Paste the envelope and select Convert only the Body when the tool detects SOAP. Turn on Strip namespaces for keys without prefixes, and list repeating elements under Always-array elements so one-item lists stay arrays.

Can I generate an XSD from XML?

Yes. Switch the output view to XSD. Types such as xs:integer, xs:decimal, xs:boolean and xs:date are inferred from every value, elements missing from some parents get minOccurs="0", and repeated elements get maxOccurs="unbounded". The schema describes your sample, so review it before using it for validation.

Can I get TypeScript or Java classes from XML?

Yes. Switch the output view to Types and choose TypeScript, Zod, Go, Python, Pydantic, Java, Kotlin or Rust. The types are inferred from the converted JSON, so the JSON options, such as key case and forced arrays, shape the generated code.

Is it safe to paste XML with a DOCTYPE?

Yes. DOCTYPE declarations are read but custom entities are never expanded and nothing is downloaded, so entity-expansion and external-entity (XXE) attacks cannot run.

Is my XML uploaded?

No. Parsing and conversion run in this browser tab, and your XML is never sent to TheVanTool’s servers.

Can’t find the tool you need?

Tell us what you’d like it to do. We’ll review your suggestion for a future tool.

Suggest a toolOpens your email app. You can also write to [email protected].