XML · July 30, 2026 · 9 min

How to Convert XML to JSON

Guide to converting XML documents to JSON for modern APIs. Online converter with attribute and array handling.

Why Convert XML to JSON?

XML dominated enterprise integrations for decades, but modern web APIs overwhelmingly use JSON. Converting XML to JSON is a common step when migrating SOAP services to REST, processing RSS feeds in JavaScript applications, or inspecting legacy config files in browser devtools.

JSON is more compact, faster to parse in JavaScript runtimes, and maps naturally to native objects. XML offers richer features like namespaces, schemas, and mixed content, but many modern tools prefer JSON for simplicity.

QuickFormat's XML to JSON converter transforms well-formed XML into formatted JSON entirely in your browser — no upload, no command-line tools required.

How Conversion Works

The converter parses XML using the browser's DOMParser, walks the element tree, and builds a JSON object. XML attributes become keys prefixed with @ (for example @id). Text-only elements become string values. Elements with both attributes and children produce objects containing both.

Repeated sibling tags automatically become JSON arrays. A catalog with multiple book elements produces "book": [{...}, {...}] instead of overwriting a single key.

Mixed content — text interleaved with child elements — produces a #text field alongside nested keys. This convention preserves information that a simple text-only mapping would lose.

Step-by-Step Conversion

Paste your XML into the XML to JSON editor or upload an .xml file via drag-and-drop. Click Convert to generate formatted JSON with 2-space indentation.

Review the output structure before using it in production code. Conversion conventions vary between tools — document your team's @attribute and #text conventions when sharing results.

Copy the JSON to Postman, a Node.js script, or documentation. Download as a .json file for test fixtures. If the XML is malformed, fix structure with the XML Formatter first.

Limitations and Alternatives

Browser-based conversion handles well-formed XML without external entity resolution or XSLT transforms. Complex enterprise documents with namespaces, xsi:type attributes, or deeply nested mixed content may need schema-aware converters for production pipelines.

This tool is ideal for inspection, prototyping, and one-off migrations. For high-volume automated conversion, consider dedicated libraries like xml2js in Node.js or Jackson XML in Java.

Read JSON vs XML for guidance on choosing formats for new projects. Explore the XML Tools hub for formatting, escaping, and conversion utilities.

Related Tools

Related Articles