Convert XML to JSON

Convert XML documents into JSON that JavaScript and modern APIs can use directly. Attributes and repeated elements are mapped predictably.

Drop your file here, or browse

Images, documents, spreadsheets, data files and subtitles. Your file stays on your device.

Your file is converted on this device and is never uploaded to a server.

Why convert XML to JSON

XML still powers RSS feeds, sitemaps, SOAP services, invoices, office documents and a lot of enterprise integration. Modern web code, however, works most naturally with JSON. Converting lets you inspect XML data quickly, feed it to JavaScript or store it in document databases.

The converter uses fast-xml-parser with settings chosen to keep information: attributes are kept as keys starting with @, element text next to attributes goes into #text, and elements that repeat become arrays. The XML declaration and processing instructions are dropped because JSON has no place for them.

XML vs JSON at a glance

Main differences between the XML and JSON formats
FeatureXMLJSON
Full nameExtensible Markup LanguageJavaScript Object Notation
TypeHierarchical markup dataHierarchical data
Introduced1998Early 2000s (RFC 4627 in 2006)
Created byW3CDouglas Crockford; now ECMA-404 and RFC 8259
StructureNested elements with attributesNested objects and arrays
CommentsYes, with <!-- -->No
Data typesText, unless an XSD schema defines typesString, number, boolean, null, object, array
Best forEnterprise data exchange, feeds and office filesAPIs, web apps and app settings
SupportEvery language; common in enterprise systemsEvery programming language
MIME typeapplication/xmlapplication/json

How to convert XML to JSON

  1. Step 1: Select the XML file

    Drop a .xml file, such as a feed, sitemap or export.

  2. Step 2: Keep JSON as the target

    JSON is preselected; CSV and YAML are also available.

  3. Step 3: Convert

    The document is parsed and each element becomes a property.

  4. Step 4: Download

    Save the pretty-printed .json file.

Mapping rules

Attributes

<item id="7"> becomes { "item": { "@id": 7 } }.

Text with attributes

Element text is stored under #text when attributes are present.

Repeated elements

Two or more siblings with the same name become an array.

Safe numbers

Plain numbers and true or false become JSON values; codes with leading zeros stay strings.

Typical XML to JSON uses

  • Reading RSS and Atom feeds. Work with feed items as JavaScript objects.

  • Legacy API migration. Inspect SOAP or XML API responses while moving to JSON.

  • Sitemap audits. Load URL lists into scripts or spreadsheets.

  • Config conversion. Move settings from XML files to JSON-based tools.

The single versus repeated element problem

XML does not say whether an element is meant to be a list. If a feed has one item, it becomes an object; with two items, it becomes an array. Code that reads the JSON should therefore handle both shapes, for example by wrapping single values in an array.

This is a limitation of converting XML without a schema, not of this tool, and every generic converter faces it.

What does not carry over

Comments, processing instructions and the XML declaration are removed. Namespace prefixes are kept as part of names, such as media:content, so you can still tell elements apart. Whitespace around text values is trimmed.

Mixed content, where text and elements are interleaved inside the same parent, is simplified: the text parts are merged into #text and their exact positions between child elements are not preserved.

  • Kept: elements, attributes, text, namespace prefixes.
  • Dropped: comments, declarations, processing instructions.
  • Simplified: mixed text and element content.

Tips for XML to JSON

  • Check that the XML is well formed; one unclosed tag stops the conversion.
  • Normalize single items to arrays in your code before looping over them.
  • Large feeds convert fine, but pretty-printed JSON can be bigger than the XML.
  • To go back, use the JSON to XML converter, which understands @ and #text keys.

XML to JSON questions

How are attributes represented?

As properties whose names start with @, for example @id or @href.

Why is one element an object and another an array?

Repeated sibling elements become arrays; a single element becomes an object. XML itself does not mark which elements are lists.

Are numbers converted?

Plain numbers and true or false values become JSON numbers and booleans. Values with leading zeros, such as 007, and very long numbers stay strings.

Is the XML declaration kept?

No. The declaration and processing instructions are dropped because JSON cannot represent them.

Does it support namespaces?

Namespace prefixes are kept in property names, for example atom:link.

Is anything uploaded?

No. Parsing happens in your browser.

Related conversions