HandyTools Hub

XML to JSON Converter

Convert between XML and JSON formats instantly

Convert XML documents to clean JSON and back again, right in your browser. Attributes, repeated elements, and mixed text are mapped with the widely used @ / #text conventions, so the round trip preserves your data. Paste an API response, a config file, or an RSS feed and get readable JSON — or turn JSON back into a valid, indented XML document in one click.

How to Use

  • Pick a direction: Use the toggle to choose XML → JSON or JSON → XML.
  • Paste your input: Drop XML or JSON into the input area (or load the sample).
  • Convert: Click convert to see the result instantly.
  • Copy or download: Copy to the clipboard or save the result as a .json / .xml file.

Features

  • Bidirectional conversion: XML → JSON and JSON → XML in one tool
  • Attributes mapped to @-prefixed keys, text content to #text
  • Repeated elements automatically become JSON arrays — and back
  • Configurable 2- or 4-space indentation for generated XML
  • Automatic escaping of &, <, >, and quotes in XML output
  • Works entirely in your browser — data is never uploaded

The @ and #text Conventions Explained

XML can express things JSON cannot: an element may carry attributes, hold text, and contain children all at once. This converter uses a popular mapping to represent that richness as plain JSON. Attributes become keys starting with @, so <user id="42"> turns into {"@id": "42"}. Text that shares an element with attributes or child nodes is stored under #text, so <price currency="USD">9.99</price> becomes {"@currency": "USD", "#text": "9.99"}. A leaf element with nothing but text collapses to a plain string, keeping simple documents simple. Because the mapping is symmetric, JSON produced this way converts back to structurally equivalent XML.

Use Cases

  • API integration: Turn XML responses from legacy or SOAP APIs into JSON for JavaScript apps.
  • Config migration: Convert XML config files (pom.xml, web.config, Android manifests) to JSON for inspection or transformation.
  • Feed processing: Parse RSS/Atom feeds into JSON objects that are easy to filter and render.
  • Data export: Generate XML from JSON when a downstream system only accepts XML.

Tips for Clean Conversions

Keep in mind that JSON object key order is preserved in modern JavaScript, so attributes always appear before child elements in the output. Everything in XML is text, so numbers and booleans arrive as strings in the JSON — cast them yourself if the type matters. When writing JSON for the JSON → XML direction, remember that keys must be valid XML names: no spaces, and they cannot start with a digit; the tool flags invalid names instead of producing broken markup. Deeply nested or huge documents convert fine, but pretty-printed JSON of a large XML file can be long — use download instead of copy for very large results.

Frequently Asked Questions

How are XML attributes represented in the JSON output?

Attributes become object keys prefixed with @. For example, <user id="42"> becomes {"user": {"@id": "42"}}. When converting JSON back to XML, any key starting with @ is written back as an attribute on the element.

What happens to repeated XML elements?

Sibling elements that share the same tag name are collected into a JSON array. <users><user>Alice</user><user>Bob</user></users> becomes {"users": {"user": ["Alice", "Bob"]}}. In the reverse direction, JSON arrays are expanded back into repeated elements.

Where does mixed text content go?

Text that sits next to child elements or attributes is stored under the special #text key. For example, <price currency="USD">9.99</price> becomes {"price": {"@currency": "USD", "#text": "9.99"}}.

Is my data uploaded to a server?

No. All conversion runs entirely in your browser using the built-in DOMParser and pure JavaScript. Nothing is sent over the network or stored anywhere.

Can I control the XML indentation?

Yes. In JSON → XML mode you can choose 2-space or 4-space indentation. The generated document always starts with a standard <?xml version="1.0" encoding="UTF-8"?> declaration, and special characters like &, <, > and quotes are escaped automatically.