XML to JSON Converter
Convert XML into structured JSON in your browser — attributes and nested elements supported.
How elements, attributes and text are mapped
The root element becomes the single top-level key. Each attribute becomes a key that starts with @, and a child element that holds only text becomes a string:
When an element has attributes and text at the same time, the text goes under a #text key next to the attributes. You'll see that in the next example.
Repeated elements become arrays, single ones don't
Two or more sibling elements with the same name are collected into an array:
Convert an order with only one item and item is an object, not a one-element array:
So the shape of the JSON depends on the data. If you write code against the output, check whether item is an array before looping over it, or wrap a lone object in an array yourself.
Every value stays a string
XML has no number or boolean types, and the converter doesn't guess. In <cfg><port>8080</port><debug>true</debug><empty/><zip>02134</zip></cfg>, the port comes out as "8080", debug as "true", and the ZIP code keeps its leading zero as "02134". An empty element such as <empty/> becomes an empty string.
Text is trimmed at both ends but spaces inside it are kept. Entities like & are decoded to the character, and CDATA content is kept as plain text.
What doesn't survive the conversion
- Text mixed with child elements. In
<p>Hello <b>world</b> and <i>you</i></p>, the loose words are dropped and only the children remain:{ "p": { "b": "world", "i": "you" } }. This converter suits data files, not documents like XHTML or DocBook. - Comments and processing instructions. These are ignored, including the XML declaration on the first line.
- Namespaces as such. Prefixes stay in the key names, for example
media:thumbnail, andxmlnsdeclarations appear as ordinary@xmlnsattributes.
Element order between different names is not recorded either. JSON objects have no reliable order, so if the sequence of mixed siblings matters, this format can't capture it.
Frequently asked questions
Why do I get Invalid XML for a page I copied from a website?+
The parser is strict XML, not HTML. Tags like br or img without a closing slash, unquoted attributes and named entities such as nbsp all make HTML invalid as XML. The input also needs exactly one root element around everything.
Does the error tell me which line is wrong?+
No. Any parsing problem gives the same Invalid XML message. To find it, cut the document down in halves until the error goes away, or check that every opening tag has a matching closing tag.
Can I turn the JSON back into the same XML?+
Partly. The JSON to XML converter reads keys starting with @ back as attributes, but it writes the #text key as an element of that name, which is not valid XML. Move that value into a regular key, or rebuild those elements by hand.
Is my XML uploaded anywhere?+
No. The conversion uses the XML parser built into your browser, so the document is read on your device.
Embed this tool on your website
Free to use on blogs, school sites and intranets. Paste this code into your page's HTML; please keep the credit line.
<iframe src="https://utilityapp.lat/embed/convert/xml-to-json" title="XML to JSON Converter" width="100%" height="600" style="border:0;max-width:760px" loading="lazy"></iframe> <p style="font-size:13px"><a href="https://utilityapp.lat/convert/xml-to-json">XML to JSON Converter</a> by UtilityApp</p>