Skip to content

Developer Tools

XML to JSON Converter

Convert XML to JSON and JSON to XML in your browser, mapping attributes and text nodes with predictable, documented rules.

XML attributes map to an @attributes key; repeated elements become arrays. Conversion runs locally via the browser XML parser.

The Structural Gap Between XML and JSON

XML has concepts JSON lacks: attributes vs element content, repeated sibling elements, namespaces, and mixed text/content. Every converter makes choices about these — attributes usually become @-prefixed keys, repeated elements become arrays (but a single occurrence may stay an object, so your consumer code must handle both). Round-tripping XML→JSON→XML rarely reproduces the original document. Use the conversion for data exchange or inspection, not as a lossless transformation, and inspect one converted node against the source before automating anything on top.

How the Tool Works

  1. Paste XML or JSON and pick the direction — or let the tool auto-detect the input format.
  2. XML attributes are preserved under a predictable @attributes key in JSON output.
  3. Repeated sibling elements become JSON arrays; single elements become object keys.
  4. Clear error messages flag malformed input with the parser’s line and column information.
Formula & Technical Standard
Element → object, attributes → @attributes, repeated children → arrays, text content → #text when mixed with children.

Example Input & Output

SOAP-style payload to JSON
Input: <user id="7"><name>Ana</name></user>
Output: {"user":{"@attributes":{"id":"7"},"name":"Ana"}}
Attributes and child elements each get their own namespace in JSON, avoiding collisions.
JSON back to XML for a legacy API
Input: {"items":[{"sku":"A1"},{"sku":"B2"}]}
Output: <items><sku>A1</sku><sku>B2</sku></items>
Arrays expand back into repeated elements, the shape most legacy XML interfaces expect.

Common Questions

Are XML namespaces preserved?

Namespace prefixes are kept as literal attribute and tag names. Full namespace resolution is intentionally out of scope to keep output predictable.

What happens to comments and processing instructions?

Comments and processing instructions are dropped during conversion because JSON has no equivalent representation.