The Free XML to JSON Converter, and JSON to XML: The Exact Mapping, the Traps, and the Fixes
A SOAP response your new app cannot read. A product feed exported as XML when your script expects JSON. A legacy system that will only accept XML, fed from an API that only speaks JSON. Converting XML to JSON and JSON to XML sounds like a single click, and it is, but the part that matters is the shape you get back. This guide explains exactly how the xml to json converter above maps attributes, text and repeated elements, how to go the other way, and where the classic traps are.

1. XML to JSON: What It Is and When You Need It
XML and JSON both describe structured data, but they think about it differently. XML, defined by the W3C XML 1.0 specification, has elements, attributes, text and ordering. JSON, defined by RFC 8259, has only objects, arrays, strings, numbers, booleans and null. Every converter has to decide how attributes, text and repeated tags should look in JSON.
You need xml to json when the data arrives as XML but the thing that consumes it wants JSON: a modern front end reading a legacy API, a script processing an export, a colleague who searches how to open XML file as JSON because the tags are hard to read. You need json to xml for the reverse: a gateway or older system that accepts XML only. This page handles both directions in one place.
2. How to Convert XML to JSON in Four Steps
Here is how to convert XML to JSON with the tool above. There is no account and no sign-up; it is an xml to json online free tool in the plain sense.
- Add your XML. Paste it into the input box, or drop a .xml, .json or .txt file onto the area marked “Drop a file or paste below”; that is the whole job when you need to convert XML file to JSON rather than pasted text.
- Choose the conversion. Pick XML → JSON in the Conversion menu. The same menu offers JSON → XML, Pretty-print XML and Minify XML.
- Decide on typing. Leave Convert numbers/booleans ticked to get real JSON numbers, true, false and null; untick it to keep every value as a string.
- Convert, then copy or download. Press Convert. The result appears in the output box with Copy and Download buttons; the download is named data.json.
3. How XML Attributes Are Represented in JSON: The Exact Rules
If you are asking how are XML attributes represented in JSON, here the answer is fixed and published. This is the tool’s sample document beside its real output:
<?xml version="1.0"?> <order id="42"> <customer>Ayesha</customer> <item sku="A1" qty="2">Notebook</item> <item sku="B7" qty="1">Pen</item> </order>
{
"order": {
"@id": 42,
"customer": "Ayesha",
"item": [
{ "@sku": "A1", "@qty": 2, "#text": "Notebook" },
{ "@sku": "B7", "@qty": 1, "#text": "Pen" }
]
}
}- The root element becomes the single top-level key (here,
order). - Attributes become keys prefixed with @, so
id="42"becomes"@id". Nothing is dropped, which is why people searching xml to json losing attributes end up here. - Text goes under #text only when the element also has attributes or child elements. An element with nothing but text, like
customer, becomes a plain value. - Repeated siblings become an array; a single child stays an object.
- Namespace prefixes stay in the key: an element written
ns:cbecomes the key"ns:c". That is the whole story for xml to json with attributes and namespaces. - CDATA is kept as text. Comments, processing instructions, the XML declaration and the DOCTYPE are dropped.
4. JSON to XML, Pretty-Print and Minify
As a json to xml converter, the tool reverses the same conventions. Here is how to convert JSON to XML: paste the JSON, choose JSON → XML, pick a root name and press Convert.
- An object with exactly one key uses that key as the root element.
- Any other object, or a top-level array, is wrapped in the root chosen in Root element name: root, data, document or items. That is the answer to the json array to xml root element question: each array entry is written as an
<item>inside it. - Keys starting with @ become attributes and
#textbecomes element text. - The output is indented two spaces, begins with a UTF-8 XML declaration, and downloads as data.xml. Invalid JSON is reported with “Invalid JSON” and the reason.
The tool doubles as an xml formatter. Choose Pretty-print XML for an xml pretty print online result: a single-line blob comes back indented two spaces per level with text trimmed. Minify XML writes the document without adding indentation. Be aware that this xml minify mode keeps whitespace already sitting between tags rather than stripping it, and both modes drop the DOCTYPE.
5. Fixing the Common XML to JSON Problems
- Xml to json single element not array: An order with one
itemgives an object; with two it gives an array. This tool cannot force a tag to always be an array, so in your code wrap a lone object in an array before looping. - Xml to json numbers converted to strings: Tick Convert numbers/booleans and plain decimal numbers, true, false and null become real JSON types. Untick it if you want everything as text.
- Xml to json leading zeros removed: Not here. A value such as
007, a postcode or an account ID stays a string even with typing on, so nothing is silently rewritten. - Xml to json #text. The
#textkey appears only where an element has both text and attributes or children. When an element mixes text and tags, all its text is joined into one#textand the original ordering is lost. - Json to xml invalid element name: JSON keys with spaces or a leading digit are written through unchanged, which produces invalid XML. Rename those keys in the JSON first; the tool does not sanitise them.
This is not an XML validator. The parser is forgiving: unclosed or mismatched tags are converted quietly rather than reported, and there is no XSD schema or DTD check, no XPath and no XSLT. For the JSON side, the JSON formatter validates and beautifies the result.
6. SOAP Responses, RSS Feeds, Sitemaps and Other Real Files
- SOAP response xml to json: Paste the whole envelope. Prefixed names such as
soap:Envelopeandsoap:Bodysurvive as keys, so your code walks down to the payload using those exact names. - RSS feed xml to json: Save or copy the feed, then paste or drop it in. Each
itembecomes an array entry once there are two or more. The tool does not fetch URLs, so it cannot pull a live feed for you. - Sitemap xml to json: The
urlentries become an array of objects withlocandlastmodvalues, easy to loop over in a link check. The namespace declaration onurlsetcomes through as an@xmlnskey, and dates stay strings. - Android strings xml to json: Each
stringelement carries a@nameand a#text, so the key and translation sit side by side, ready to reshape for a translation workflow. - Maven pom xml to json: Two or more dependencies become an array of objects with groupId, artifactId and version; a POM with a single dependency gives one object instead. Comments in the POM are dropped.
Need a different format next? For xml to yaml, convert here to JSON, then paste the result into the YAML to JSON converter and switch it to JSON to YAML. For a spreadsheet, turn a flat JSON array into rows with the CSV to JSON converter, then finish in the spreadsheet converter. To see what changed between two exports, the diff checker compares them line by line.
7. Why Cortexis Is the Best Free XML JSON Converter
Plenty of pages offer an xml json converter. Few tell you what the output will look like. Here is what is different.
Both directions on one page
XML to JSON, JSON to XML, pretty-print and minify share one input box, so a round trip needs no second website.
A documented, predictable mapping
Attributes use @, text uses #text, repeated elements become arrays. The rules are published above, so you can code against them.
Types handled carefully
Numbers, true, false and null become real JSON types when you want them, while values like 007 keep their leading zeros as strings.
Your data stays private
Files and pasted text are never stored on our servers and nothing is retained after your session, which matters for API responses and customer exports.
Nothing is used for training
Your XML and JSON are never used to train any model.
Honest about its limits
No validation, no XSD, no XPath, no URL fetching, and we say so. Where another tool does the job, this guide links to it.
It is one of a wider set of free developer and document tools built on the same terms.
8. Frequently Asked Questions (FAQ)
How do I convert XML to JSON for free?
Paste your XML into the tool at the top of this page, or drop in an .xml file, choose XML to JSON and press Convert. Copy the result or download it as data.json. There is no account and no sign-up.
How are XML attributes shown in the JSON?
Each attribute becomes a key with an @ prefix, so id="42" turns into "@id". When the same element also has text, that text is stored under #text next to the attributes.
Why is one element an object and another an array?
Repeated sibling elements become an array, while a single element stays an object. This is the array-of-one problem, and the tool cannot force a tag to always be an array. Handle it in your code by wrapping a lone object in an array before looping over it.
Will numbers and leading zeros be kept correctly?
With Convert numbers/booleans ticked, plain decimal numbers, true, false and null become real JSON types. Values with leading zeros, such as 007 or many postcodes, stay strings so they are never altered.
Can I convert JSON back to XML?
Yes. Choose JSON to XML, pick a root name if needed, and press Convert. Keys starting with @ become attributes, #text becomes element text, and a top-level array is wrapped in your chosen root with each entry written as an item element.
How do I use the converted JSON in my code?
Copy the output or download data.json, then read it with your language's standard JSON parser, such as JSON.parse in a web app or json.loads in Python. Access attributes by their @ keys, for example order["@id"]. Wherever a tag can appear once or many times, wrap a lone object in an array before looping.
Does the tool check whether my XML is valid?
No. The parser is forgiving and converts unclosed or mismatched tags without reporting them, and there is no XSD schema or DTD check. If validity matters, check the XML against its schema first. To validate the JSON result, use the JSON formatter.
Can it load XML from a URL or an RSS feed address?
No. Input is pasted text or a file you add. Save the feed, sitemap or API response first, then paste or drop it into the tool.
Is it safe to convert API responses or customer data here?
Your files and pasted text are never stored on our servers, nothing is retained after your session, and nothing is ever used for training. The result is yours to copy or download.
Next step? Validate the JSON with the JSON formatter, encode a value for a request with the Base64 encoder and decoder or the URL encoder, or turn SQL INSERT statements into CSV rows with the SQL to CSV converter. Browse other formats in the file converter hub, or learn to build tools like this in our free full-stack web development course.

