XML to JSON Converter

Convert well-formed Extensible Markup Language (XML) to JavaScript Object Notation (JSON). Paste XML and tap the convert button.

Paste a well-formed XML document to create a readable JSON representation. The conversion runs locally in your browser and keeps your input on this page.

Use one well-formed XML document with a single root element. Attribute values, element text, and repeated sibling elements are represented in the JSON output.



Question

What is converting Extensible Markup Language (XML) to JavaScript Object Notation (JSON)?

Converting XML to JSON means reading a well-formed XML document and writing a JSON representation of the same element tree. This tool runs in your browser, keeps the XML on this page, and writes pretty-printed JSON into the output box. Empty input or invalid XML returns an empty JSON object, {}, with a status message explaining what to fix.

The converter keeps the XML document element as the top-level JSON property. Each child element becomes a property named after the element tag, and nested elements are converted recursively. Text nodes are trimmed and stored under _text, attributes are grouped under _attributes, and repeated sibling elements with the same name are collected into arrays.

For example, <book id="1"><title>XML Guide</title></book> becomes a JSON object whose book value contains _attributes for id and a nested title object with _text. This compact shape is useful for quick inspection, examples, API debugging, documentation snippets, and moving simple element-and-attribute data into tools that expect JSON. Use the copy, select, or download controls after conversion when you need to reuse the output.

XML and JSON do not have identical data models, so the result is a practical representation rather than a universal standard mapping. XML namespaces, comments, processing instructions, CDATA boundaries, entity declarations, DTD validation, schema types, mixed-content ordering, and insignificant whitespace are not preserved as first-class JSON features by this page. Review the output before using it in automated workflows, especially for namespaced documents, mixed text-and-element content, or systems that require a specific XML-to-JSON convention.

This is a conversion and inspection tool, not an XML validator, sanitizer, security scanner, or schema-aware migration utility. Treat XML from untrusted sources as untrusted data, and validate the generated JSON against the requirements of the destination system before storing or executing anything derived from it.


Question

What is Extensible Markup Language (XML)?

XML, or Extensible Markup Language, is a W3C-recommended markup language for representing structured information in text. XML documents describe a tree made from elements, attributes, character data, comments, processing instructions, and optional declarations.

A well-formed XML document has exactly one document element, matching start and end tags, properly nested elements, case-sensitive names, and correctly escaped special characters. Raw < and & characters cannot appear as ordinary text; they must be represented with entity or character references when they are not markup.

XML can model information that JSON does not represent directly, including attributes, namespaces, mixed text-and-element content, entity references, processing instructions, document type declarations, and schema-governed vocabularies. A generic converter must choose a JSON convention for those features, which is why XML-to-JSON output can differ between tools.

XML itself defines syntax and processing rules, not application meaning. The receiving application, schema, or document format decides what each element and attribute means and whether a converted representation is acceptable.


Question

What is JavaScript Object Notation (JSON)?

JavaScript Object Notation, or JSON, is a lightweight, text-based data interchange format. RFC 8259 and ECMA-404 define JSON syntax for structured data made from objects, arrays, strings, numbers, booleans, and null.

JSON objects contain name/value pairs, and arrays contain ordered values. Those structures can be nested to represent records, lists, configuration data, API payloads, and other common interchange shapes. This tool writes the converted XML tree as formatted JSON with indentation so the result is easier to read and copy.

JSON is language independent, but it has interoperability details worth remembering. Member names should be treated as unordered, duplicate names can be ambiguous, and all data types in the generated JSON are determined by the converter's mapping rather than by XML schema information. Text from XML remains text unless another application interprets it as a number, boolean, date, or other domain-specific value.


Lightbulb

References