What is JSON ↔ XML?
JSON ↔ XML is a browser-based converter that translates data between JSON and XML in either direction. Paste JSON to get an equivalent XML document, or paste XML to get structured JSON. It uses a documented convention: arrays become repeated sibling elements, and XML attributes are represented as keys prefixed with @_.
JSON and XML are the two most common data-interchange formats, and developers frequently need to bridge between them — consuming an XML SOAP API from a JSON-oriented codebase, migrating legacy XML configuration to JSON, or preparing test fixtures in whichever format a tool expects. Doing that translation by hand is tedious and error-prone, especially for nested structures.
Because the two formats do not map onto each other perfectly, this is a best-effort structural conversion rather than a guaranteed lossless round-trip. Everything runs locally in your browser — your data, which may include API payloads or configuration, is never uploaded.
Why use JSON ↔ XML?
Converting instantly between JSON and XML removes a real friction point. When you receive XML from a legacy service but your application speaks JSON, or you need to feed a JSON dataset into an XML-based system, this tool gives you the translated structure in one paste instead of hand-editing tags and braces.
Understanding the conversion convention makes the output predictable. Knowing that arrays turn into repeated elements and attributes become @_ keys lets you anticipate exactly what you will get, so you can adjust your JSON or XML input to produce the shape you need on the other side.
Local conversion protects your data. XML and JSON payloads often carry sensitive fields — customer records, credentials, internal identifiers. This tool processes everything in your browser and sends nothing to a server, which you can confirm in the Network tab while converting.
Features
- Convert JSON to XML with arrays mapped to repeated elements
- Convert XML to JSON, with attributes exposed as @_ keys
- Live conversion as you type
- Clear, specific error messages for malformed input
- One-click copy of the result to your clipboard
- Download the result as .xml or .json depending on direction
- Handles nested objects and deeply structured documents
- Runs entirely in your browser — no uploads, works offline
How to use JSON ↔ XML
- Choose JSON → XML to convert JSON into XML, or XML → JSON to go the other way.
- Paste your source data into the input panel on the left.
- The converted result appears in the right panel automatically as you type.
- If the input is malformed, a clear error message appears below the tool describing the problem.
- Copy the result to your clipboard, or download it as an .xml or .json file.
Example 1 — JSON to XML
Paste a JSON object and get an equivalent XML document wrapped in a root element.
Input
{"a":1}Output
<root>
<a>1</a>
</root>Example 2 — XML to JSON
Switch to XML → JSON and paste XML to receive structured JSON. Text values come back as strings.
Input
<root><a>1</a></root>Output
{
"a": "1"
}Common Mistakes
- Expecting a perfect lossless round-trip: JSON and XML have different data models. A single-item array in JSON cannot be distinguished from a scalar after conversion to XML, so it may not come back as an array. Treat this as a structural bridge, not a reversible transform.
- Losing type information: XML has no native concept of numbers or booleans, so values converted from XML to JSON come back as strings. A number like 1 in XML becomes the string "1" in JSON. Re-cast types in your own code if you need them.
- Forgetting the attribute convention: XML attributes are represented as @_name keys in JSON. If you do not account for that prefix, your code will look for the wrong key and miss attribute values.
- Missing or multiple root elements: valid XML requires exactly one root element. Pasting a fragment with several top-level elements, or none, will fail to convert.
- Namespaces and mixed content: XML namespaces, processing instructions, comments, and mixed text-plus-element content do not map cleanly to JSON and may be dropped or flattened unexpectedly.
- Assuming attribute vs child-element choices are preserved: whether a value was an attribute or a child element in the original XML is a design decision that cannot always be recovered when converting back.
Developer Tips
- When consuming an XML API from JSON-first code, convert a sample response here to see exactly how attributes (@_ keys) and repeated elements (arrays) will appear before writing your parsing logic.
- Remember that all XML-to-JSON values are strings — add explicit Number() or Boolean() conversion in your code for fields you expect to be typed.
- To force something to become a JSON array reliably, make sure there are at least two sibling elements of that name in the XML, since a single element is ambiguous.
- Format the resulting JSON with the JSON Formatter or validate it with the JSON Validator to confirm the converted structure matches the contract you expect.
- For complex XML with namespaces or attributes, convert a small representative fragment first to understand the mapping before running your full document through.
Frequently Asked Questions
- Why is the conversion not perfectly reversible?
- JSON and XML have fundamentally different data models. JSON distinguishes arrays, objects, numbers, booleans, and null; XML has elements, attributes, and text, but no native arrays or number types. Because of this mismatch, some information is inevitably ambiguous when translated — a single repeated element cannot be told apart from a scalar, and types collapse to strings. The tool does a faithful structural conversion, but it is a bridge, not a lossless round-trip.
- Why do my numbers become strings when converting XML to JSON?
- XML has no concept of data types — every value between tags is just text. When that text is converted to JSON, there is no reliable way to know whether "1" was meant as the number 1, the string "1", or a boolean-like flag, so the converter preserves it safely as a string. If you need typed values, cast them explicitly in your own code after conversion, using functions like Number() or by checking against known field names.
- What does the @_ prefix mean in the JSON output?
- When XML is converted to JSON, element attributes are distinguished from child elements by prefixing their keys with @_. For example, <item id="5"> becomes { "item": { "@_id": "5" } }. This convention lets a single JSON object represent both the attributes and the child content of an XML element without them colliding. When converting JSON back to XML, keys starting with @_ are emitted as attributes.
- Is my data uploaded to a server?
- No. All conversion happens locally in your browser using JavaScript. Your JSON and XML — which may contain API payloads, configuration, or sensitive records — are never sent to a server, logged, or stored. You can confirm this by opening your browser's Network tab while converting: there are zero outbound requests, and the tool continues to work even offline.
- How are JSON arrays represented in XML?
- A JSON array is converted into repeated sibling elements with the same tag name. For example, { "items": [1, 2] } becomes two <items> elements inside the parent. The consequence is that when converting back from XML, a single occurrence of an element is ambiguous — it could be a one-item array or a scalar — so it typically returns as a scalar rather than a one-element array. Having two or more siblings reliably produces an array.
- Can it handle XML namespaces and attributes?
- Attributes are handled and exposed as @_ keys, so they are preserved through conversion. Namespaces, processing instructions, comments, and mixed content (text interleaved with child elements) are more complex and do not have a clean JSON equivalent, so they may be flattened or dropped. For documents that rely heavily on namespaces, review the converted output carefully rather than assuming a perfect mapping.
- What happens if my input is invalid?
- The converter validates the input before transforming it. Invalid JSON (a missing brace, trailing comma, or single quotes) or invalid XML (an unclosed tag, multiple root elements, or a missing root) produces a clear error message below the tool instead of a silent or misleading result. Fix the reported problem in the input and the conversion updates live as you type.