XML to JSON
Convert XML data into JSON format, turning it into a structure that is easy to use in code. No signup. Ideal for working with XML data as JSON.
Result
Share on Social Media:
Paste your XML into this free XML to JSON converter and get clean, indented JSON in seconds — with attributes turned into _-prefixed keys and repeated tags turned into arrays. It runs entirely in your browser, with no account, no install and no upload: you can also load XML from a .xml file.
On this page
- How to Convert XML to JSON Step by Step
- What XML and JSON Are
- XML Versus JSON
- Who Converts XML to JSON
- Pro Tips for XML to JSON
- Common XML to JSON Mistakes to Avoid
- Related Tools You May Need Next
- Frequently Asked Questions
How to Convert XML to JSON Step by Step
- Paste your XML into the input box. The box is labelled "Enter or Paste XML". It starts empty — there is no sample to delete first. Make sure the XML is well formed: every tag closed, properly nested, and a single root element.
- Or upload a file. Click Upload File to load a .xml file from your computer — the tool reads it into the input box for you. If it says "Invalid File", paste the XML text in directly instead.
- Click "Convert to JSON". That single button is the whole conversion. There are no settings to choose — no indentation option, no attribute option, nothing to configure.
- Read the Result. The result appears below the input: your JSON in an editor, indented for readability. The page scrolls down to it automatically. You can switch the editor between code, tree, form, text and view modes if you want a different way to read it.
- Copy it or save it. Click Copy to Clipboard to copy the whole result, or Save as TXT to download it as a file. Note the download is named xml-json.txt — rename it to .json if the system you are feeding needs that extension.
- Check it before you use it. Read the output once: confirm the structure, the arrays and any empty strings match what your code expects — especially if your XML had a single item where you expected a list, or numbers you need as numbers.
The "Load from URL" box does not load XML. The page has a box for pasting a web address, but it will not fetch XML from it — nothing appears in the input. If your XML lives at a URL, open it, copy the XML text, and paste it into the input box instead.

What XML and JSON Are
XML and JSON are two ways of writing the same structured data. XML is tag-based: every value sits between an opening and a closing tag, nested in a hierarchy. JSON is compact: keys and values in curly braces, arrays in square brackets. They can hold the same information — this tool rewrites one as the other.
| Your XML | What the JSON looks like |
|---|---|
| Element with text | A key with that text as a string: <title>Dune</title> → "title": "Dune". |
| Numbers and booleans | They stay strings: <price>9.99</price> → "price": "9.99", and <available>true</available> → "available": "true". The tool does no type conversion. |
| Nested element | A nested object. |
| Element repeated two or more times | An array, one entry per element. |
| Element appearing only once | A plain value, not an array — one <item> gives a string, two give an array. Check which one you got. |
| Attribute | Becomes a key starting with an underscore: <person id="42"> → "_id": "42". Attribute keys appear after the child elements in the output. |
| Element with an attribute and text | Both are kept: <a x="1">hello</a> → {"_x": "1", "__text": "hello"}. |
| Empty element <note/> | An empty string: "note": "". |
| CDATA section | Becomes plain text — the markup inside it is not parsed and no CDATA marker is kept. |
| Comments, processing instructions, DOCTYPE | Dropped — they do not appear in the JSON at all. |
| Namespace prefix <ns:tag> | The prefix is stripped from the element name; it is recorded only as a "__prefix" value. |
| Mixed content (text around a child tag) | The text is merged into a single "__text" value — check it, because its position relative to the child tag is lost. |
| Special characters (& < > " ') | Decoded automatically back to the plain characters. |
| Surrounding whitespace | Trimmed from values. |
| XML declaration <?xml ...?> | Accepted and ignored — it does not appear in the output. |
There is no fixed wrapper. Your XML's root element becomes the top-level key in the JSON. There is no added declaration and no renamed root — what you paste is what the structure follows.
Worked example: a book object, converted for real
Paste this XML:
<book><title>Dune</title><authors>Frank Herbert</authors><authors>Brian Herbert</authors><price>9.99</price><available>true</available><note/></book>
Click "Convert to JSON" and you get exactly this — the result editor shows it indented with two spaces:
| Line | JSON |
|---|---|
| 1 | { |
| 2 | "book": { |
| 3 | "title": "Dune", |
| 4 | "authors": [ |
| 5 | "Frank Herbert", |
| 6 | "Brian Herbert" |
| 7 | ], |
| 8 | "price": "9.99", |
| 9 | "available": "true", |
| 10 | "note": "" |
| 11 | } |
| 12 | } |
Three things to notice: the two <authors> elements became an array; 9.99 and true came back as strings, not a number and a boolean; and the empty <note/> became an empty string. This is the same book data the JSON to XML tool converts the other way — and the round trip is not type-perfect: a number, a boolean and a null went in there, and strings and "" came back here.

XML Versus JSON
You convert when the other side needs JSON. Plenty of modern code speaks JSON only — web APIs, JavaScript, configuration you edit by hand — and if your data is in XML, converting is the bridge. XML is what older systems produce; JSON is what your code will accept.
| Aspect | XML | JSON |
|---|---|---|
| Structure | Tags in a nested hierarchy | Keys, values and nesting in braces |
| Syntax | Verbose — <name>Ada</name> | Compact — {"name": "Ada"} |
| Arrays | Repeated elements, one per item | Square brackets, one list |
| Attributes | Native attributes on any element | No native attributes — they become "_id" keys |
| Comments | <!-- comments --> are supported | None — JSON has no comments |
| Data types | Everything is text | Strings, numbers, booleans and null — but this tool outputs strings only |
| Best for | Legacy systems, SOAP, documents, feeds | Web APIs, JavaScript, config you edit by hand |
This tool versus JSON to XML
| Aspect | XML to JSON (this tool) | JSON to XML |
|---|---|---|
| Direction | XML in, JSON out | JSON in, XML out |
| Input | Plain text box, or a .xml file | Code editor, a .json file, or a JSON address |
| Output | JSON in an editor (code, tree, form, text or view mode) | XML in a code editor |
| Wrapper | None — your root element is the top key | Fixed <root> element plus an XML declaration |
| Numbers and booleans | Become strings ("9.99", "true") | Become plain text (9.99, true) |
| Empty values | An empty element becomes "" | A null becomes a self-closing tag |
| Attributes | Become "_id" keys | "_id" keys become attributes |
| Repeated items | Repeated elements become an array | An array becomes repeated elements |
| Where it runs | In your browser — nothing is uploaded | In your browser — nothing is uploaded |
Converting one way and back does not restore the original types: numbers and booleans come back as strings, and a null comes back as an empty string. If your code needs real numbers, convert the strings after pasting the JSON in.
Who Converts XML to JSON
Developers consuming a legacy API. An older service returns XML; your JavaScript or Python code wants JSON. Convert the response once and work with it as an object.
API integrators. Moving data between an XML-based partner and a modern JSON API, one payload at a time.
Data migrators. Turning XML exports — feeds, sitemaps, configuration files — into JSON for import into tools that read JSON.
QA and testers. Producing JSON test fixtures from XML samples to check how a system handles them.
Students and learners. Seeing, side by side, how the same data looks in XML and in JSON — nesting, attributes, arrays and all.

Pro Tips for XML to JSON
Tidy your XML first. Paste it into the XML Formatter before converting. Invalid XML shows an "Invalid XML" message and no result at all — the tool will not guess what you meant.
Check whether you got a single value or an array. One <item> gives a plain string; two give an array. If your code expects a list, handle both shapes — or add a second element before converting.
Convert the string numbers back in code. Every value in the output is a string, including "9.99" and "true". Parse them into numbers or booleans where your code needs the real type.
Rename the saved file. "Save as TXT" downloads xml-json.txt. The contents are JSON, so rename it to .json if the system you are feeding expects that extension.
Paste directly when a URL load does nothing. The "Load from URL" box does not fetch XML addresses. Open the address, copy the XML text, and paste it into the input box instead.
Switch the result editor to tree view for large output. The result opens in code mode; the tree view makes a big nested document much easier to scan.
Keep the original XML. The conversion drops comments, processing instructions and namespace prefixes, and turns every value into a string. Keep the source file so you can go back to it.
Common XML to JSON Mistakes to Avoid
Pasting invalid XML and expecting a result. A missing closing tag, a mismatched tag or an unclosed quote shows an "Invalid XML" message and produces no JSON. Fix the XML first — the XML Formatter can tidy it, but it will not repair broken syntax for you.
Expecting numbers and booleans to stay typed. <price>9.99</price> becomes "price": "9.99" — a string. Code that adds two such "numbers" will join them as text instead. Convert them after pasting.
Assuming one element always gives an array. A single <item> gives a plain value, not a one-item array. Code that loops over the result will break on the single-item case — check the shape first.
Trying to load XML from a URL. The "Load from URL" box does not load XML addresses — nothing appears in the input box. Copy the XML text from the address and paste it in instead.
Expecting the saved file to be .json. "Save as TXT" downloads xml-json.txt. If you hand that filename to a tool expecting .json, rename it first.
Expecting CDATA or namespace prefixes to survive. CDATA becomes plain text with no marker, and a namespace prefix is stripped from the element name. If either matters to your code, keep the original XML alongside the JSON.
Pasting two top-level elements, or bare text. XML needs exactly one root element. Two elements side by side, or text with no tags at all, shows "Invalid XML". Wrap everything in a single root element first.
Related Tools You May Need Next
Prepare the XML, convert it, then check the JSON:
JSON to XML — convert back the other way, from JSON to XML. XML Formatter — tidy XML into a readable layout before converting. JSON Formatter — tidy the JSON output afterwards. JSON Validator — confirm the JSON output is valid. JSON Viewer — read and navigate large JSON output. JSON Editor — edit the JSON output in a full editor. JSON Beautifier — pretty-print JSON. JSON Minify — shrink the JSON output by removing whitespace. JSON Escape — escape or unescape JSON strings. JSON to CSV — the same data as a spreadsheet instead. JSON to YAML — the same data as YAML instead. CSV to JSON — build JSON from a CSV first, then work with it. Schema Markup Generator — structured data for your pages.
Frequently Asked Questions
How do I convert XML to JSON?
Paste your XML into the input box and click "Convert to JSON". The result appears below the input — JSON in an editor, indented for readability. Then copy it with Copy to Clipboard or download it with Save as TXT.
Do I need an account or anything installed?
No. The converter is free, needs no signup and nothing to install, and the conversion runs in your browser on any device.
Is my XML uploaded to a server?
No. The conversion runs in your browser with JavaScript; your pasted XML is never sent to SEOMagnate's server. The only network request the tool makes is the optional file read, which happens on your own computer.
What does the JSON output look like?
Your root element becomes the top-level key, nested elements become nested objects, and the JSON is shown indented with two spaces. There is no added wrapper and no renamed root — the structure follows your XML.
How are XML attributes converted?
An attribute becomes a key starting with an underscore: <person id="42"> becomes "_id": "42". Attribute keys appear after the child elements in the output. An element with both an attribute and text keeps both, with the text under "__text".
What happens to numbers in my XML?
They become strings: <price>9.99</price> gives "price": "9.99", and true gives "available": "true". The tool does no type conversion, so convert the strings back into numbers or booleans in your code where you need the real type.
How are repeated elements handled?
An element that appears two or more times becomes an array, one entry per element. But an element that appears only once becomes a plain value, not a one-item array — so check whether you got a single value or a list before using the result.
Can I load XML from a file or a URL?
From a file, yes: click Upload File for a .xml file. If it says "Invalid File", paste the XML text in directly instead. From a URL, no — the "Load from URL" box does not fetch XML addresses, so copy the XML text from the address and paste it in.
Why did I get "Invalid XML"?
The XML is not well formed: a missing closing tag, a mismatched tag, two top-level elements, bare text with no tags, or an empty input all give that message and no result. Fix the XML — the XML Formatter can tidy it — and try again.
Can I convert JSON back to XML?
Yes — use the JSON to XML tool, which converts in the opposite direction. Note the round trip is not type-perfect: numbers and booleans come back as strings, and a null comes back as an empty string.