Convert XML to JSON with attributes, arrays and types under your control
The XML to JSON converter reads any well-formed XML — SOAP and REST responses, RSS and Atom feeds, sitemaps, KML and GPX tracks, Maven and .NET configuration files, Android layouts — and turns it into clean JSON for JavaScript, Python or a document database. Paste XML or open a file and the JSON updates as you type.
XML has features JSON does not, so every converter has to pick a convention. Here you decide: attributes as @name keys, with a prefix of your own or grouped in one _attributes object; the key that holds element text; when to create arrays; whether 42 and true become a number and a boolean; and whether namespace prefixes, CDATA sections, comments and the exact order of mixed elements survive.
Your XML is read by the browser’s built-in, standards-compliant parser, so mistakes are reported with the line and column where they occur. Nothing is uploaded.
How to use the XML to JSON Converter
- Paste XML into XML input, drop a file onto the box or press Open file.
- Choose how Attributes appear in the JSON and set the Text node key.
- Decide when to create Arrays: only for repeated elements, for every element, or for names you list, such as
item, entry. - Tick the options you need — convert numbers and booleans, strip namespace prefixes, keep CDATA or comments, preserve element order — and pick an indent.
- Press Copy or Download JSON, or Swap to rebuild XML from the result in the JSON to XML converter.
XML to JSON Converter features
A real XML parser
All five predefined entities, numeric character references such as ₹, entities declared in an internal DTD, CDATA and namespaces are handled as the XML 1.0 and Namespaces specifications describe.
Predictable arrays
One <item> normally becomes an object while two become an array — a classic source of bugs. Make every element an array, or only the names you list, and your code always sees the same shape.
Careful type conversion
With “Convert numbers & booleans”, 499, 12.50 and true become JSON values. Text like 007, True or integers beyond 253 stays a string, so nothing is silently altered.
Namespaces your way
Keep qualified names such as media:thumbnail together with their xmlns declarations, or strip the prefixes for short, simple keys.
Preserve element order
In a document like <p>Hi <b>there</b>!</p> a keyed object loses the interleaving. The ordered form keeps every element, text run, CDATA section and comment in sequence.
Exact error locations
Unclosed or mismatched tags, a bare &, undefined entities like and duplicate attributes are shown with the line, column and a snippet.
How XML maps to JSON with the default settings
Indentation between elements is ignored, and text inside an element is trimmed unless you untick “Trim whitespace in text”. Processing instructions such as <?xml-stylesheet?> are left out because JSON has nothing to hold them. If the XML itself needs checking or tidying first, open it in the XML Formatter.
| XML | JSON |
|---|---|
<name>Dune</name> | "name": "Dune" |
<book id="1">Dune</book> | "book": {"@id": "1", "#text": "Dune"} |
Two <tag> siblings | "tag": ["a", "b"] |
<owner/> or <owner></owner> | "owner": "" |
<![CDATA[x < y]]> | "x < y", or {"#cdata": "x < y"} when kept |
| A comment | left out, or "#comment": " note " when kept |
<p>Hi <b>there</b></p> with order preserved | [{"p": [{"#text": "Hi"}, {"b": [{"#text": "there"}]}]}] |
Good settings for common kinds of XML
Need a table rather than nested JSON? XML to CSV flattens repeating records into rows, and XML to YAML gives a lighter, comment-friendly format for configuration.
- RSS and Atom feeds — list
item, entry, categoryas always-array names so a feed with one post has the same shape as one with fifty. - SOAP responses — tick “Strip namespace prefixes” to turn
soap:Envelopeandns2:PriceintoEnvelopeandPrice. - Configuration and sitemaps — converting numbers and booleans helps with
<port>8080</port>or<enabled>true</enabled>; leave it off for PIN codes, ZIP codes, phone numbers and IDs. - Documents with mixed text (XHTML fragments, DocBook, legal markup) — use “Preserve element order”.
- SQL Server
FOR XMLoutput — keep “Decode _xHHHH_ names” on, soUnit_x0020_Pricebecomes"Unit Price".
XML to JSON Converter FAQ
How do I convert XML to JSON?
Paste the XML into the input box or open an .xml file. The XML to JSON conversion runs instantly; choose your attribute and array settings, then copy the JSON or download it as a .json file.
Why is one element an object but several an array?
XML does not say whether an element is a list, so converters only create an array when an element repeats. Choose “Always (every element)” or list specific names under “For the names I list” to get arrays even when there is one item.
How are XML attributes shown in JSON?
By default as keys starting with @, for example "@id": "1". You can use another prefix such as - or @_, group them in an _attributes object, or leave them out.
Are numbers converted automatically?
Only if you tick “Convert numbers & booleans”. XML stores everything as text, so the safe default keeps values as strings; with the option on, plain decimal numbers and the words true and false become JSON numbers and booleans.
What happens to namespaces?
Prefixed names and their xmlns declarations are kept as they are, so the JSON can be turned back into equivalent XML. Tick “Strip namespace prefixes” to drop the prefixes and declarations.
Can I turn the JSON back into XML?
Yes — press Swap to open the result in the JSON to XML converter with the same attribute and text conventions. Keep CDATA and comments, and preserve element order, if you need the closest possible round trip.
Is my XML sent to a server?
No. Parsing and conversion run entirely in your browser, so tokens in SOAP headers, internal configuration and customer data stay on your device.