/

XML to JSON

Processed Client Side

Convert XML markup into equivalent, readable JSON — attributes, text nodes, and nesting preserved.

XML · 12 lines
12 lines · 297 chars
Length: 297Lines: 12Size: 297 BytesCursor: 1:1
JSON
JSONattributes → @, text → #text
jsonLength: 358Lines: 20Size: 358 BytesCursor: 1:1

Bookmark this tool now — skip the search next time you need it.

About XML to JSON

This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.

Convert XML markup into equivalent JSON, preserving attributes, text content, and nesting rather than flattening them away. The two formats do not map onto each other perfectly — XML distinguishes between an attribute and a child element, and JSON has no such concept — so the conversion follows the widely used convention of prefixing attribute names with @ and storing element text under a #text key. That keeps the round trip meaningful instead of silently dropping half the document. Type inference is optional, so numeric and boolean strings can become real JSON values or stay as text, depending on what the receiving code expects. Parsing uses the browser XML parser rather than a regular expression, which is why a malformed document is reported as an error instead of converting into something that looks plausible and is wrong.

Key features

  • Converts any well-formed XML document into equivalent JSON
  • Attributes preserved with an @ prefix, so they stay distinguishable from child elements
  • Element text preserved under a #text key when an element has both attributes and content
  • Nesting and repeated elements preserved as nested objects and arrays
  • Optional type inference, turning numeric and boolean strings into real JSON values
  • Parse errors reported when the XML is not well formed, using the browser own XML parser rather than pattern matching
  • The root element becomes the single top-level key, so the name of the document survives the conversion
  • Syntax-highlighted panes for both the XML input and the JSON output
  • Runs entirely in your browser — no upload, no size limit imposed by a server

How to use it

  1. Paste your XML into the input pane.
  2. Decide whether you want type inference on or off.
  3. Click Convert.
  4. Read the JSON, then copy it.

Tips & common mistakes

  • Turn type inference off when the XML holds identifiers, postcodes, or version strings — inference will read 1.10 as the number 1.1 and lose the distinction.
  • The @ prefix on attributes and the #text key are conventions, not a standard. If a downstream system expects different markers, rename them after converting.
  • XML is stricter than JSON about being well formed: one unclosed tag fails the whole document. The error message names the position, which is usually enough to find it.
  • An element that appears once becomes an object and the same element appearing twice becomes an array. Code consuming the result has to handle both, which is the classic XML-to-JSON trap.
  • Namespace prefixes are kept as part of the key name, so an element like soap:Body becomes a key containing a colon — quote it when accessing it in JavaScript.
  • Comments and processing instructions are not carried across, so keep the original XML if those matter.
  • Whitespace between elements is not meaningful in most XML dialects but is preserved inside text content, so an element indented across several lines keeps those newlines in its #text value. Trim it in your own code if it matters.
  • SOAP and RSS documents convert well and are the usual reason to reach for this, but both lean heavily on namespaces — check that the prefixed keys survive into whatever consumes the JSON before you rely on it.

Related tools

Browse all 2 XML tools

Frequently asked questions

9

Paste your XML document into the input pane and press Convert. It is parsed with the browser’s native XML parser and converted into equivalent JSON.

Attributes are placed under keys prefixed with @, so <book id="1"> becomes { "@id": 1 }. Element text content is stored under a #text key when the element also has attributes or children.

Repeated sibling elements with the same tag name are automatically collected into a JSON array.

The XML must be well-formed. A single unclosed or mismatched tag will produce a parser error instead of partial output — check that every tag is properly closed.

Attribute names are prefixed with @ so they stay distinguishable from child elements, and element text is stored under a #text key when an element has both attributes and content.

An element appearing once becomes an object; the same element appearing twice becomes an array. This is the classic XML-to-JSON trap, and consuming code has to handle both.

Yes for identifiers, postcodes, and version strings — inference reads 1.10 as the number 1.1 and loses the distinction. Leave it on when the data really is numeric.

They are kept as part of the key name, so an element like soap:Body becomes a key containing a colon. Quote it when accessing the property in JavaScript.

No. Comments and processing instructions are not carried across, so keep the original XML if those matter to you.