Home/Formats/XML to JSON
Converter · XML → JSON

Convert XML
to JSON.

Turn an XML document into clean, typed JSON — attributes preserved under @attributes, element text under #text, repeated tags folded into arrays, and numbers and booleans converted to real JSON types. Paste XML below for an instant result in your browser, or upload files here. Free, no signup.

Free · Paste or upload · 20 MB · batch of 5 · Files auto-deleted after 1 hour.

01 — Convert Ready

Drop XML files here, or click to browse.

XML → JSON · up to 5 files · 20 MB each

No signup · Private upload · Files deleted after 1 hour

⌘↵ to run Files deleted after 1 hour

Paste XML, get JSON instantly

Runs entirely in your browser — what you paste never leaves your machine. Same mapping rules as the file converter above; use the uploader for large files or batches.


    

Why convert XML to JSON?

How the XML → JSON mapping works

Every converter has to decide how XML's attributes, text, and repeated elements land in JSON. Here's exactly what this one does:

So this XML:

<book id="1"><title>Dune</title><inStock>true</inStock></book>

becomes this JSON:

{ "book": { "@attributes": { "id": "1" }, "title": "Dune", "inStock": true } }

How it works

  1. Use the converter. Go to the Formatly XML to JSON converter page. No registration is required.
  2. Upload your XML file. Drag and drop your XML document into the uploader, or browse from your device.
  3. Convert to JSON. Select JSON as the target format and click the Convert button.
  4. Download the JSON file. Click the Download button to save the converted JSON document.

Good for

XML to JSON in code — PHP, JavaScript, Python

Converting in a script instead? The usual one-liners: in PHP, json_encode(simplexml_load_string($xml)) (attributes land under @attributes, like here); in Node.js, the xml2js or fast-xml-parser npm packages; in the browser, DOMParser plus a small walk of the tree — that's exactly what the paste tool above does; in Python, xmltodict.parse(). For a one-off feed or API response, pasting it above is faster than wiring up a parser.

FAQ

Can I convert XML to JSON without uploading a file? Yes. Paste your XML into the instant converter on this page and the JSON appears as you type. The paste tool runs entirely in your browser, so the XML never leaves your machine. Use the file uploader for large files or batches.

How are XML attributes handled? Attributes are collected into an @attributes object on the element they belong to, so nothing is lost. If an element also has text, that text is placed under a #text key alongside @attributes. A plain element with only text becomes that value directly.

Are numbers and booleans converted to real JSON types? Yes. Text that looks numeric becomes a JSON number, true and false become booleans, and an empty element becomes null. Everything else stays a string. One caveat: a value like 007 is read as the number 7, so if leading zeros matter, keep that field as text in the source.

What happens to repeated tags? Repeated sibling elements with the same tag become a JSON array. Three <item> elements under a parent turn into an item array; a single occurrence stays a single object. The whole document is wrapped in one object keyed by the root element's tag.

Can I convert JSON back to XML? Yes. Use the JSON to XML converter for the reverse direction. Note that a round-trip won't always be byte-identical, because JSON has no separate notion of attributes versus child elements.

Is my data secure? Files are processed over an encrypted connection and automatically deleted after 1 hour. No signup is required and files are never used to train any AI model.

Related