XML to JSON ConverterONLINE

Convert well-formed XML into JSON locally, keeping attributes and text distinct.

1 MiB per input · Ctrl / ⌘ + Enter to run

Elements become keys, repeated siblings become arrays, attributes use @attributes, and text uses #text. DTD declarations are rejected.

Result
Ready. Paste input, then run the tool.
Your JSON stays in your browser. Core processing happens locally.
THE PRACTICAL GUIDE

Convert XML elements and attributes into predictable JSON

XML to JSON maps a well-formed XML document into a predictable JSON structure. It keeps attributes distinct from element text, while repeated sibling elements become arrays.

When should you use it?

  • Inspect a vendor XML response as JSON.
  • Move simple XML records into an API pipeline.
  • See where XML attributes and text land in a JSON mapping.
WORKED EXAMPLE

Example: XML attributes remain distinct

The attribute stays a string under @attributes; element text is kept separately under #text.

XML input
<person id="7">Alex</person>
JSON output
{
  "person": {
    "#text": "Alex",
    "@attributes": {
      "id": "7"
    }
  }
}

Understand the mapping before consuming the output

XML has attributes and text content as well as child elements. This tool places attributes under @attributes and text under #text; repeated elements become arrays. Values remain strings because the text 00123 does not reveal whether its meaning is a code or a number. Review the mapping with a small representative XML document before applying application-specific conversions.

Mixed content needs particular care

A paragraph can alternate text and child elements, such as an emphasized word in a sentence. An object mapping cannot preserve every aspect of that ordering. Namespaces and an external schema can also carry meaning that a generic conversion does not infer. DTD input is rejected. Use a schema-aware integration when exact XML document semantics are required rather than relying on a generic data view.

AT THE WORKBENCH

Bring an XML document into a JSON workflow.

Convert a local XML document into a predictable JSON shape, then review its attributes, text nodes, and repeated elements before using it in an application.

  1. Paste or open XML

    Use a well-formed document up to 1 MiB.

  2. Convert locally

    The parser keeps values as strings and reports malformed XML.

  3. Review the mapping

    Copy or download the JSON and adjust its shape for your application.

IN PRACTICE

How do XML attributes and repeated elements appear in JSON?

The converter places attributes under @attributes, element text under #text when needed, and repeated sibling elements in an array. All XML text remains strings, so an attribute id="007" does not unexpectedly become the number 7.

XML with an attribute and repeated children

xml
<team id="007">
  <member>Alex</member>
  <member>Sam</member>
</team>

The JSON root is team; id is under @attributes, and member is an array of string values.

No. It is a practical object mapping, not a lossless XML document model. DTD declarations are rejected, and namespace or schema semantics require separate application logic.

BEFORE YOU USE THE RESULT

What should you check before using the result?

DTD declarations are rejected. Comments, processing instructions, mixed-content order, namespaces, and XML schema types are not preserved; review the mapping for your application.

Mapping rules

The root element name becomes the top-level key. Attributes live under @attributes, text with child elements under #text, and repeated sibling names become arrays. Text and attribute values remain strings to avoid changing identifiers or large numbers.

XML features this tool excludes

DTD and entity declarations are rejected. Mixed-content order, comments, processing instructions, namespace interpretation, and XML schema types are not preserved. This general mapping is different from this site’s typed JSON-to-XML export format.

Compare JSON and XML

Technical reference: JSON syntax and interoperability · RFC 8259

THE JSON FIELD GUIDE
All guides