XML to/from JSON

Convert XML to JSON or JSON to XML instantly in your browser. Free, no-upload tool for developers handling API data, configs, and legacy formats.

What XML to/from JSON Does

It parses an XML string into a structured JSON object — mapping attributes to @attributes, repeated sibling tags to arrays, and text-only nodes to typed primitives — or serializes a JSON object into well-formed, indented XML with attributes, text content, and nested elements reconstructed from the same key conventions.

Who Uses This Tool

XML to/from JSON is built for Backend developers, frontend engineers, API integrators, data engineers, QA engineers, DevOps engineers working with configuration files. Whether you are processing data as part of an automated pipeline or need a quick one-off conversion in your browser, the tool requires no installation and no account — paste your input and get your result in seconds.

Primary Use Case

Converting a legacy XML API response into JSON so it can be consumed by a modern JavaScript application or REST client.

The Problem It Solves

Manually rewriting XML structures as JSON — or JSON back into XML — by hand is tedious and breaks silently: attributes get dropped, repeated sibling tags collapse incorrectly into flat keys, and text node types (booleans, numbers, nulls) stay as strings. This tool removes that entire class of structural and type-fidelity errors by handling attribute mapping, array promotion, type inference, and XML escaping automatically.

Example

Input
<user id="1"><name>John</name><admin>true</admin></user>
Output
{
  "user": {
    "@attributes": {
      "id": 1
    },
    "name": "John",
    "admin": true
  }
}

What to Do With the Output

Paste into a JavaScript codebase as a parsed data object, drop into a Postman request body, store in a JSON config file, feed into a data pipeline or ETL process, plug into an API mock definition, or send to an XML-required endpoint after reverse-converting from JSON.

Common Mistakes to Avoid

Common mistakes or gotchas: Pasting input without switching the mode toggle first — the tool converts in one direction only per session. Passing a root-level JSON array instead of an object — XML requires a single root element, so the top-level JSON value must be a keyed object. Assuming a single <item> tag and two <item> tags behave the same — a lone tag produces an object, but two siblings of the same name collapse into an array. Expecting XML namespaces to be resolved — namespace prefixes are preserved as literal key strings (e.g. "soap:Body"), not parsed as namespace declarations. Overlooking that "true", "false", "null", and numeric strings in XML text nodes are auto-cast to their JSON equivalents — this can cause type mismatches if the downstream system expects strings.

How It Works

In XML → JSON mode, the browser's native DOMParser with "application/xml" builds a DOM tree. The tool walks each node recursively: element attributes are collected into @attributes, trimmed text content in leaf nodes is passed through parseValue to infer boolean, null, number, or string types, child elements sharing a tag name are promoted to arrays on second occurrence, and mixed-content nodes store inline text under #text. In JSON → XML mode, JSON.parse deserializes the input, then a recursive buildXml function serializes each key: @attributes keys emit as inline XML attributes, #text emits as inline element content, arrays repeat the parent tag per item, and all values are XML-escaped (&amp;, &lt;, &gt;, &quot;, &apos;). Output is indented at two spaces per depth level. All logic executes client-side — no data leaves the browser.

Pro Tip

Use the JSON → XML direction to round-trip data through a JSON-native store (e.g. MongoDB or a NoSQL cache) and reconstruct attribute-bearing XML on output. By preserving @attributes keys in your stored JSON, you can emit fully valid, attribute-annotated XML from a system that never natively handled XML — without hand-authoring a single tag.

Also Known As

XML to/from JSON is also commonly referred to as xml2json, json2xml, XML to JSON parser, JSON to XML serializer, XML JSON transformer, convert xml to json free, xml to json online, json to xml online, xml json converter. All of these terms describe the same conversion — no matter what you call it, this tool handles it.

Frequently Asked Questions

Attributes on any XML element are grouped into an @attributes object nested inside that element's JSON key. On the reverse conversion, any @attributes object in JSON is serialized back as inline attributes on the XML opening tag.
The first occurrence is stored as a single object or primitive. When a second sibling with the same tag name is encountered, both values are wrapped in a JSON array, and all further occurrences are pushed into that array.
XML requires exactly one root element. A top-level JSON array or primitive has no natural mapping to a single XML root tag, so the tool rejects it. Wrap your content in a root key: { "root": [ ... ] }.
No. Both conversion directions run entirely in the browser using DOMParser and JSON.parse. No input or output is transmitted or stored.
Yes. Text content that matches "true", "false", or "null" is cast to the corresponding JSON type. Valid numeric strings become JSON numbers. All other values remain strings.
Yes. Switch to JSON → XML mode and paste the JSON output. Round-trip fidelity is maintained as long as the JSON retains @attributes and #text keys from the original conversion.