What is an XML to JSON converter?
XML and JSON are two ways of writing the same thing: structured data. XML is the format of older systems, config files, feeds, and documents; JSON is the format of modern APIs and JavaScript apps. When data arrives as XML and the destination speaks JSON, something has to translate — and that is what this converter does.
The translation turns elements into objects. The default text on this page, <person><name>Ada</name><age>36</age></person>, becomes {"person":{"name":"Ada","age":36}} — the same data, in JSON shape. The element names become keys, the text inside them becomes values, and the nesting stays exactly where it was.
XML has features JSON does not have, so the converter has to make choices. Attributes become keys with an @ in front, repeated elements become arrays, and text that looks like a number becomes a number. Those choices are the standard conventions, and they are stated plainly below so nothing surprises you.
Everything runs in your browser. Your data never leaves your device, nothing is uploaded or stored, and there is no account to create. You can convert sensitive records — customer data, private config, internal feeds — without worrying about who else sees them.
How XML becomes JSON
The converter reads your XML with a small hand-written parser built for this page. It walks the text tag by tag: opening tags, closing tags, self-closing tags, comments, and CDATA sections. If the tags do not match up — a closing tag that does not match its opening tag, or a tag left open at the end — it reports the error instead of guessing.
Each element becomes an object keyed by its tag name. A text-only element becomes a plain value: <age>36</age> becomes the number 36, because the text looks like a number. An element with children becomes an object whose keys are the child tag names. An empty element like <empty/> becomes null, which is the honest JSON way to say the element had no content.
Attributes become keys with an @ prefix. <book id="1"> becomes {"@id": "1"} inside the book object, sitting next to the child elements. The @ keeps attributes visibly separate from elements, so you can always tell which was which in the original XML.
Repeated elements become arrays. Two <book> elements under <books> become a JSON array with two entries, in the same order. A single <book> stays a single object, not a one-item array — the converter only makes an array when it actually sees a repeat.
The small parser, and what it handles
This converter uses a small recursive parser written for standard XML, not a full XML engine. It handles the parts of XML that real data actually uses: elements, attributes, text, self-closing tags, comments, processing instructions, and CDATA sections. It decodes the five standard entities — <, >, &, ", and ' — back into plain characters.
It also handles mixed content honestly. If an element has both text and child elements, the text goes under the key #text, next to the child keys. That way nothing is silently dropped — the text is still there, clearly labelled as text rather than as a child element.
There are limits, and they are worth knowing. The parser does not read DTDs or external entities, and it does not resolve namespaces — a tag like <svg:rect> keeps its full name, prefix and all. Those features belong to full XML engines, and this page is a converter, not a browser-grade parser.
If your XML uses a feature outside that list, the converter will either report an error or produce a result that needs a second look. Check the output against the input when the XML is unusual — the counts above the output box tell you how many elements and attributes were found, which is a quick sanity check.
A worked example: a person, then a book list
Start with the default text: <person><name>Ada</name><age>36</age></person>. The converter produces {"person":{"name":"Ada","age":36}} — 3 elements, 0 attributes. The name stayed a string and the age became the number 36, because the text looked like a number. That typing rule is what makes the JSON useful in code instead of a pile of strings.
Now a list with attributes: <books><book id="1"><title>Dune</title></book><book id="2"><title>Emma</title></book></books>. The result is {"books":{"book":[{"@id":"1","title":"Dune"},{"@id":"2","title":"Emma"}]}} — 5 elements, 2 attributes. The two <book> elements became an array, and each id became an @id key. Read it out loud and it says the same thing as the XML.
Try the edge cases: <root><empty/><note><![CDATA[a < b]]></note></root>. The result is {"root":{"empty":null,"note":"a < b"}} — 3 elements, 0 attributes. The self-closing element became null, and the CDATA text came through with its < intact, because CDATA means 'read this as text, not markup'.
Finally, try broken XML: <person><name>Ada</person>. The converter reports a mismatched closing tag — </person> for <name> — instead of producing JSON. There is no honest way to convert a document whose tags do not match, so the tool refuses and points at the problem.
Who converts XML to JSON, and why
Developers working with legacy systems are the biggest users. Old APIs, feeds, and config files speak XML, while the code that consumes them speaks JSON. Converting the payload once, at the boundary, is far easier than teaching every part of the app to read XML.
Testers are the second group. They capture XML responses from an old endpoint and need JSON versions to feed into a new test harness. Converting by hand is slow and error-prone; pasting the block here and copying the result takes seconds and cannot introduce a typo.
Data workers are a third group. Migrations and imports often need XML on one side and JSON on the other. A converter turns an XML export into JSON that a modern pipeline can read, without a spreadsheet in between and without retyping anything.
Students are a fourth group. Comparing the same data in XML and JSON side by side is the fastest way to understand both formats. The converter shows the mapping in action: elements to objects, attributes to @keys, repeats to arrays — and the differences between the two formats become obvious.
XML to JSON vs JSON to XML
The two directions are mirror images, but they are not symmetric. Converting XML to JSON is the harder direction, because XML has attributes, mixed content, and repeated elements that JSON has no direct home for. That is why this converter has rules — @ for attributes, arrays for repeats, #text for mixed text — and states them plainly.
Use this converter when the destination needs JSON: a modern API, a JavaScript app, a data pipeline. Use the reverse converter when the destination needs XML: a legacy system, an old config format, a feed. The data is the same; only the audience changes.
Checking the input first is good practice in both directions. A JSON formatter prints the result neatly so you can read it before using it, and an HTML encoder decoder handles the escaped characters that XML and HTML share. Read the data, then convert it — the converter is the second step, not the first.
Moving the result safely is another job. A base64 encoder decoder turns the JSON into a single safe string for transport, and a text formatter cleans up plain text that came out of a document. Convert first, then move it — in that order.
Common conversion mistakes
The most common mistake is expecting numbers to stay strings. This converter turns text that looks like a number into a real number: <age>36</age> becomes 36, not "36". That is usually what you want, but if a value like a postcode or a phone number must stay a string, check the output — 01234 would become the number 1234, and the leading zero would be lost.
Second: assuming attributes and elements are the same. In the output, <book id="1"> gives {"@id": "1"}, while <book><id>1</id></book> gives {"id": 1}. The @ marks the difference, and code that reads the JSON must look for the right key. If you ignore the @, you will read the wrong field.
Third: forgetting that a single repeated element stays an object. One <book> becomes an object, not a one-item array — the array only appears when a second <book> shows up. Code that always expects an array will break on a feed with a single item. Check for both shapes, or normalise after converting.
Fourth: converting broken XML and expecting the tool to fix it. A converter cannot repair mismatched tags or an unclosed element. If the tool reports an error, fix the tags it points to and convert again. The error message is the help, not the obstacle.
How to use this XML to JSON converter
Using this converter is simple. Paste your XML into the box, or type it directly. The JSON appears instantly in the box below, with the element and attribute counts shown above it. There is no button to press and no form to submit.
To use the result, select the text in the output box and copy it. To convert another block, select all, delete, and paste the new one — the counts reset instantly. If the XML is invalid, the output box shows the error message instead; read it, fix the tags it points to, and paste again.
Everything runs in your browser. No sign-up, no account, no data sent anywhere — your XML never leaves your device. It works offline once the page has loaded, so you can use it on a plane, in a server room with no signal, or anywhere else you move data between systems.
Try it with something real before you need it: paste an XML response from a feed you use and read the JSON it becomes. Once you have used it twice, the mapping — elements to objects, attributes to @keys, repeats to arrays — becomes second nature, and the format gap stops being a chore.