Developer

XML to JSON Converter — Two-Way Formatter

Convert XML to readable JSON or JSON back to formatted XML, preserving attributes, text values, nested elements, and repeated sibling arrays.

100% Client-SideNo Data StoredFree ForeverNo Signup
XML ↔ JSON Converter
XML attributes use keys beginning with @, text mixed with child elements uses #text, and repeated sibling elements become JSON arrays. Mixed-content ordering, comments, and processing instructions are not preserved.

How to Use XML to JSON Converter

  1. 1

    Choose XML to JSON or JSON to XML and paste data, or load the small example.

  2. 2

    Select Convert and correct any parser message if the input is invalid.

  3. 3

    Copy the formatted result, or swap the output into the reverse direction for a round-trip check.

About XML to JSON Converter

This two-way XML and JSON converter is intended for APIs, configuration files, test fixtures, data migration, documentation, and debugging. XML and JSON have different data models, so a transparent mapping is more useful than pretending every document can round-trip perfectly.

Mapping used by this converter

  • The XML document element becomes the single top-level JSON key.
  • Attributes use an @ prefix, such as @id.
  • Repeated sibling tags become arrays.
  • Plain leaf text becomes a JSON string.
  • Text stored alongside attributes or child elements uses #text.
  • A JSON array produces repeated elements when converted to XML.

JSON-to-XML validates element and attribute names, escapes text and attribute values, formats indentation, and adds an XML declaration. XML-to-JSON rejects malformed documents and DOCTYPE declarations before walking the DOM.

Some XML features have no lossless equivalent in ordinary JSON. Comments, processing instructions, entity declarations, CDATA boundaries, namespace semantics, and mixed text/element ordering are not preserved. Numbers, booleans, and null-like text read from XML remain strings because XML alone does not declare their JSON types. For schema-driven production transformations, use an XML-aware library with rules for your specific document format.

The parser and formatter run entirely in the browser. Data is rendered into text areas, never injected as live HTML, and is not sent to a conversion API.

FRI

Built by

Fateh Raiyan Ishmum

Full-stack dev since 2020. Full-stack web developer since 2020. Builds privacy-first, open-web tools. Specialises in Next.js, TypeScript, and performance-focused design.

Frequently Asked Questions

Attribute names receive an @ prefix. For example, <book id="7"> becomes a book object with "@id": "7". This keeps attributes distinct from child elements that may use similar names.

Repeated sibling elements with the same tag name become a JSON array. When converting back, any JSON array under an element key produces repeated XML elements in the same array order.

No. It focuses on data-shaped XML. Comments, processing instructions, CDATA boundaries, namespace semantics, and the exact order of text interleaved with child elements are not round-tripped. The page explains the mapping before conversion.

A well-formed XML document requires exactly one root element. The converter therefore uses the single top-level JSON key as that root and reports a clear error if the object has zero or multiple root keys.

Conversion uses the browser's DOMParser and local JavaScript. Input is not uploaded by this tool. DOCTYPE declarations are rejected, and converted content is displayed as text rather than executed as markup.

More Free Tools