UtilityKit

500+ fast, free tools. Most run in your browser only; Image & PDF tools upload files to the backend when you run them.

XML to JSON Converter

Convert simple XML into structured JSON with optional attribute support and text trimming.

About XML to JSON Converter

XML was the dominant data interchange format for two decades and still powers SOAP APIs, RSS feeds, SVG files, Android resources, Maven POM files, and countless legacy enterprise systems. When you need to consume XML in a JavaScript or Python application, or migrate data out of an old system, you need it as JSON. Parsing XML manually means dealing with attributes vs text nodes, self-closing tags, mixed content, namespaces, and CDATA sections that wrap escaped HTML — none of which map cleanly to JSON without a deliberate strategy. This tool converts XML to JSON using a consistent attribute-aware strategy: element attributes become @attr keys, text content becomes a #text key, and repeated sibling elements become arrays. The result is a predictable, queryable JSON structure you can immediately work with using standard JavaScript or jq.

Why use XML to JSON Converter

Attribute-Aware Mapping

XML attributes are preserved as @attr prefixed keys rather than being silently dropped. This gives you access to the full information in the original XML, including IDs, types, and namespace declarations that live in attributes.

Repeated Element Arrays

Sibling elements with the same tag name are automatically grouped into a JSON array. This prevents the common mistake of losing data when multiple child elements share a tag and only the last one survives the conversion.

CDATA Handling

CDATA sections that contain escaped HTML or other character data are extracted and placed as string values in the JSON. The CDATA wrapper is removed cleanly without exposing its syntax in the output.

Namespace Aware

XML namespace prefixes and xmlns declarations are preserved in the JSON key names, letting you distinguish soap:Body from wsdl:message without collisions in complex enterprise XML formats.

Compact Mode

When a tag contains only text and no attributes or children, it can be emitted as a plain string value rather than a {#text: '...'} wrapper object, producing cleaner JSON for simple XML documents.

Browser-Local

Conversion runs entirely in your browser. SOAP request logs, Android resources, and legacy data exports never leave your machine or touch a server.

How to use XML to JSON Converter

  1. Paste your XML document or fragment into the input editor
  2. Choose how attributes are represented: as @attr prefixed keys or as nested objects
  3. Select whether to compact single-value arrays or always emit arrays for repeated elements
  4. Click Convert to generate the JSON equivalent
  5. Review the output to confirm attribute handling and text nodes match your needs
  6. Copy the JSON and use it with your JavaScript code, jq queries, or data pipeline

When to use XML to JSON Converter

  • You are consuming a SOAP API and need to parse the XML envelope response in JavaScript
  • You are processing an RSS or Atom feed and want a JSON structure you can iterate over
  • You are migrating data from a legacy XML-based export to a modern JSON-based system
  • You need to inspect an Android resource file or Maven POM as JSON in a query tool
  • You received an XML response from a legacy enterprise API and need to feed it into a REST pipeline
  • You want to use jq or JSONPath to query data that is currently locked in XML format

Examples

Simple element to object

Input: <user id="1"><name>Alice</name><role>admin</role></user>

Output: { "user": { "@id": "1", "name": "Alice", "role": "admin" } }

Repeated elements become array

Input: <items><item>A</item><item>B</item><item>C</item></items>

Output: { "items": { "item": ["A", "B", "C"] } }

CDATA section unwrapped

Input: <message><body><![CDATA[<b>Hello</b>]]></body></message>

Output: { "message": { "body": "<b>Hello</b>" } }

Tips

  • After conversion, pipe the JSON through UtilityKit's JSON Formatter to validate structure and explore with folding.
  • If repeated elements are not becoming arrays, check whether the input truly has sibling elements or whether they are wrapped in a parent container.
  • Strip XML namespaces with a find-and-replace before converting if namespace prefixes create noisy key names in the output.
  • For SOAP envelopes, navigate directly to the Body element after conversion rather than parsing the full envelope structure.
  • Test the converter with a small representative sample before processing a large XML export to verify attribute and array handling.

Frequently Asked Questions

How are XML attributes represented in the JSON?
Attributes are added as keys prefixed with @ to distinguish them from child elements. For example, <user id='1'> becomes {"@id": "1"}. This convention is used by many XML-to-JSON libraries including xml2js.
What happens when the same child element appears multiple times?
Repeated sibling elements with the same tag are grouped into a JSON array automatically. This prevents silent data loss from the last-value-wins problem that affects naive converters.
How are text nodes handled when an element has both text and children?
Mixed content — elements with both text and child elements — places the text in a #text key alongside the child element keys. This matches xml2js and similar library conventions.
Does it handle XML namespaces?
Namespace prefixes are preserved in key names (soap:Body stays as "soap:Body") so that namespace-qualified elements do not collide. xmlns declarations become @xmlns or @xmlns:prefix keys.
Can it convert SVG files to JSON?
Yes. SVG is valid XML and the converter handles it correctly. However, SVG JSON is rarely the goal — this is most useful when you need to programmatically inspect SVG structure rather than render it.
How are CDATA sections handled?
CDATA sections are unwrapped and their content is placed as a plain string value. The CDATA delimiters (<![CDATA[ and ]]>) are removed from the output.
Are XML processing instructions and comments included?
By default, processing instructions and comments are excluded from the JSON output. They carry no data semantics and would clutter the resulting structure.
Can I convert the JSON back to XML?
The conversion is lossy for some XML features, so round-tripping is not guaranteed to reproduce the original file exactly. For lossless XML processing, use an XML library or XSLT transformation.

Explore the category

Glossary

XML element
The fundamental building block of XML, consisting of an opening tag, optional content and child elements, and a closing tag. Elements form the hierarchical structure of an XML document.
XML attribute
A name-value pair placed inside an element's opening tag that provides metadata about the element. Attributes are distinct from child elements and are preserved as @attr keys in the JSON output.
CDATA section
A special XML syntax (<![CDATA[...]]>) that tells parsers to treat the enclosed content as raw character data, not markup. Commonly used to embed HTML or other XML-like content without escaping.
Namespace
An XML mechanism for qualifying element and attribute names with a URI prefix to avoid naming collisions, typically written as prefix:localname. Used extensively in SOAP, XHTML, and SVG.
Mixed content
An XML element that contains both text and child elements. Mixed content requires special handling during conversion since JSON objects cannot natively represent an ordered mix of text and element nodes.
SOAP
Simple Object Access Protocol — an XML-based messaging protocol used in enterprise web services. SOAP responses are XML documents with a defined Envelope/Body structure.