XML ↔ JSON

XML ↔ JSON Converter

Paste XML or JSON and convert in either direction with a clear, consistent mapping. Errors point to the line and column, special characters are escaped correctly, and unsafe XML constructs are rejected. Nothing is uploaded.

Back

Convert

No DTDs · no external entities
Paste XML or JSON, then choose a direction.

Conversion format

  • Element → key with the element name: <title>Hi</title> ⇄ "title": "Hi"
  • Attribute → key starting with @: <book id="1"> ⇄ "@id": "1"
  • Text next to attributes or child elements → "#text" (several text runs → array)
  • Repeated sibling elements → array: <a>1</a><a>2</a> ⇄ "a": ["1", "2"]
  • Empty element ⇄ null; all XML values stay text strings

Comments, processing instructions and the exact position of text in mixed content don’t survive a round trip. DOCTYPE and entity declarations are rejected.

About this tool

About XML ↔ JSON Converter

XML ↔ JSON Converter converts XML documents to JSON and JSON back to XML using one documented mapping: attributes become “@” keys, text next to attributes or children becomes “#text”, and repeated sibling elements become arrays. XML is parsed by the browser’s XML parser after rejecting DOCTYPE and entity declarations; JSON is parsed by a strict parser with line-and-column errors. Output is formatted and checked before it is shown.

Many systems still exchange XML (feeds, SOAP services, configuration and office formats) while modern APIs and tools prefer JSON. Converting with a predictable mapping makes it easy to move data between them and to inspect XML in JSON-friendly tools, without uploading the data.

How to use

Step by step

  1. Paste XML into the left box or JSON into the right box, or press Load sample.
  2. Choose the indentation and whether to trim whitespace around XML text.
  3. Press XML → JSON or JSON → XML.
  4. If an error appears, read the line and column and use Go to error.
  5. Review any notes about dropped comments or mixed content.
  6. Copy the result or download it as .xml or .json.
Key features

What it offers

  • Two-way conversion in separate editable panels
  • Documented mapping for attributes, text, repeated and nested elements
  • Strict XML and JSON parsing with line and column errors
  • DOCTYPE, entity and DTD declarations rejected for safety
  • Correct XML escaping and validation of element names
  • Unicode preserved; invalid XML characters reported
  • Formatted output with indentation choice
  • Copy, Download .xml, Download .json and sample data
Best practices

Tips for best results

  • Keep a copy of the original XML if comments or processing instructions matter.
  • Wrap lists in a parent element so repeated items are easier to handle as arrays.
  • Make sure JSON keys are valid XML names before converting to XML.
  • Treat all converted values as text and convert types in your own code if needed.
  • Validate the converted output in the system that will consume it.
Benefits

Why people use it

Predictable

One consistent, documented mapping both ways.

Safe parsing

No DTDs or external entities are ever loaded.

Exact errors

Line and column for parsing problems.

Private

Conversion runs entirely in your browser.

FAQ

Common questions

Attributes become keys starting with “@” (for example "@id": "b1"). An element that has only text becomes a plain string. When an element has attributes or child elements as well as text, the text goes under "#text".
Sibling elements with the same name become a JSON array under one key. An element that appears only once becomes a single value — so a list with one item is not an array.
No. XML has no data types, so every value is kept as a text string. When converting JSON to XML, numbers and true/false are written as text.
Comments, processing instructions and the XML declaration are dropped, CDATA becomes plain text, and in mixed content (text between child elements) the text is kept but its exact position is not. Whitespace around text is trimmed unless you turn that option off.
Documents with a DOCTYPE, entity or other DTD declarations are rejected, so no external DTD is loaded and no custom entity is expanded. The browser’s XML parser only builds data — nothing in the XML or JSON is executed.
An object with one top-level key becomes the root element. Anything else — several top-level keys, an array or a single value — is wrapped in a <root> element. Keys must be valid XML names, and arrays inside arrays can’t be represented.
Yes. Unicode text is kept as is, and &, <, > and quotes are escaped in the XML output. Characters that XML 1.0 forbids, such as most control characters, are reported instead of being written.
Private by design

This runs entirely in your browser

No file or text you enter here is uploaded. Encoding and decoding happen on your device using native browser APIs — close the tab and nothing remains on a server.

Install Toolisco Add it to your device for offline, one-tap access.