XML ↔ JSON Converter
Convert XML to JSON or JSON back to XML. Handles attributes, text nodes, and arrays sensibly.
Enter input above to see the result.
What is this for?
XML and JSON are the two dominant data interchange formats, and you regularly need to translate between them—migrating from a SOAP API to REST, plumbing legacy feeds into a modern stack, or simply reading XML in a tool that only speaks JSON. The mapping is opinionated rather than reversible-by-default, because XML has features (attributes, mixed content, ordered children) that JSON fundamentally lacks. This tool uses the conventional fast-xml-parser-style mapping: attributes get a configurable prefix (default @), text nodes go to a key (default #text), and repeated child elements collapse to arrays. Both directions run entirely in your browser with no server round-trip.
When to use it
- Converting an RSS, Atom, or SOAP response into JSON to consume in a JavaScript application.
- Generating XML configuration from a JSON template—build configs, Spring beans, Maven POMs, or Office Open XML scaffolds.
- Quickly extracting nested values: convert XML to JSON, then use any standard JSON query or manipulation tool you already know.
- Round-tripping data to confirm the structure survives conversion, or debugging shape mismatches between systems.
- Normalising XML from multiple sources before ingesting into a JSON-native database or API.
- Prototyping XML-to-object mappings before committing to a formal schema or serialiser.
How it works
- XML to JSON: The browser's native XML parser reads your input, then walks the tree. Element attributes become object keys with your chosen prefix (default
@). Element text content goes to a text key (default#text). Child elements with the same tag name are collected into an array; a single child remains an object. - JSON to XML: Your JSON is validated as an object with exactly one root key (which becomes the root element). That key's value is recursively unpacked: nested objects become child elements, keys starting with your prefix become attributes, and the text key becomes element text. Arrays expand to repeated elements.
- Configuration: You can customise the attribute prefix and text node key before conversion. Use
@or$for attributes; use#textor_for text. Changing these is essential if your XML naturally contains keys that would collide with your chosen markers. - Validation: Malformed input (broken XML or invalid JSON) produces an error message pointing to the line. Valid structure is required before conversion proceeds.
Common gotchas
- Single child vs array. A document with one
<item>becomes{"item": {...}}; the same document with two becomes{"item": [{...}, {...}]}. Consumers must handle both shapes, or normalise arrays on the way in. - Mixed content collapses. An element like
<p>hello <b>world</b>!</p>cannot round-trip cleanly—interleaved text and inline elements have no natural object representation. Use this tool only for data-centric XML, not narrative markup. - Element order is lost. JSON objects do not guarantee key order in all contexts. If your XML has order-significant siblings (e.g., a sequence of steps), JSON is the wrong destination; consider keeping it as XML or using an ordered array wrapper.
- Attribute prefix collisions. If an XML element has a child element whose name starts with your chosen prefix, the conversion will fail or produce ambiguous output. Change the prefix (e.g., to
$or_attr) to avoid this. - Numbers and booleans aren't auto-coerced. XML text is always a string;
"1"stays"1"in JSON, and"true"remains a string. Parse or coerce types in your application code if needed. - JSON to XML requires a single root. XML demands exactly one root element. Your input JSON must be an object with exactly one top-level key. Wrap arrays or multiple roots in a container first.
Tips for smooth conversions
- Preview your output before using it downstream. Small structural differences can compound in larger pipelines.
- If converting back and forth, keep a reference copy of the original to spot what didn't round-trip.
- For large documents (several MB), this tool may slow down; consider a CLI tool like
jqor Node.jsfast-xml-parserif performance becomes critical.