XML <-> JSON Converter

Convert XML to JSON and vice versa

Loading editor...
Loading editor...

XML to JSON Converter — Transform XML Data to JSON Format

Understanding the Basics

Converting XML to JSON is one of the most common data transformation tasks in modern integration work. Legacy enterprise systems, SOAP APIs, RSS feeds, and configuration systems produce XML, but modern JavaScript frontends, mobile apps, and microservices prefer JSON. The conversion requires careful handling of XML-specific constructs that have no direct JSON equivalent: XML attributes must be mapped to JSON properties (typically with an "@" prefix convention or merged into the element object), text content of elements containing both attributes and text must be mapped to a special "$text" or "#text" field, and XML's ability to have multiple sibling elements with the same tag name must be resolved into JSON arrays. In enterprise data pipelines and serverless functions, parsing XML adds unnecessary latency and processing overhead. Translating it to lightweight JSON makes processing and querying much more efficient. CDATA sections become string values. XML namespaces and processing instructions require explicit decisions about inclusion or exclusion. Our converter uses the fast-xml-parser library with sensible defaults: attributes are merged into the element object, repeated elements become arrays, and text-only elements produce string values. The output is formatted JSON ready for use in JavaScript applications, REST APIs, or NoSQL databases.

How to Use the Tool

  1. Paste your XML document into the input editor.
  2. Configure attribute handling: merge attributes into the element object (default) or prefix with @ symbol.
  3. Click "Convert" — the XML is parsed and the hierarchy is mapped to JSON objects and arrays.
  4. Review the JSON output: XML elements become object keys, attributes become properties, and repeated elements become arrays.
  5. Copy or download the JSON for use in your application, API, or data pipeline.

Key Features & Specifications

  • Handles XML attributes by merging them into the element's JSON object
  • Converts repeated sibling elements with the same tag name into JSON arrays
  • Preserves text content in mixed-content elements using a #text convention
  • Strips or preserves XML namespace declarations based on configuration
  • Outputs pretty-printed, syntax-highlighted JSON for immediate readability

Frequently Asked Questions (FAQ)

Q:How are XML attributes represented in the JSON output?
By default, attributes are merged directly into the element's JSON object alongside child element keys. To disambiguate between an element named "id" and an attribute named "id", enable the @ prefix mode which produces "@id" for attributes in the resulting object.
Q:What happens with an XML element that has both text and child elements?
This is "mixed content" — the element has both text nodes and element children. The text is placed in a special "#text" key and child elements appear as normal JSON properties within the same object.
Q:Can I convert the JSON back to XML?
Yes. Use our JSON to XML tool which reverses the transformation, converting JSON objects back to XML elements and attributes. The round-trip is not guaranteed to be byte-identical but will be semantically equivalent.