XML TO JSON CONVERTER
What is XML to JSON conversion?
XML to JSON conversion turns an XML document into an equivalent JavaScript Object Notation (JSON) value. XML is a document-oriented markup language built around nested elements and attributes. JSON is a lightweight, data-oriented format made of objects, arrays, strings, numbers, booleans, and null values.
Developers convert XML to JSON when a modern system, JavaScript application, REST API, or automation pipeline expects JSON but the source data still arrives as XML. Legacy enterprise systems, SOAP web services, configuration files, RSS and Atom feeds, and many government and financial data sources still expose XML. Converting those documents into JSON makes them usable in Node.js, browser code, and countless tools that speak JSON natively.
A trustworthy converter must do more than rename angle brackets into curly braces. It has to decide how XML attributes become JSON properties, how repeated elements become arrays, how empty elements are represented, and how text values map to JSON values — all without silently dropping information. This tool applies a fixed, deterministic set of rules so the same XML always produces the same JSON.
HOW TO CONVERT XML TO JSON
How to convert XML to JSON online
- Paste XML into the editor or choose a local
.xmlfile. Drag and drop is supported. - Click Convert to JSON. If the XML is malformed, the tool reports a useful error with line and column information when available.
- Choose 2-space or 4-space indentation for the output JSON.
- Review the JSON preview and any conversion notes.
- Copy the JSON or download it as a
.jsonfile.
The source XML is never sent to an API. Validation, parsing, and JSON serialization all happen in the current browser tab.
XML TO JSON ONLINE
Why use a browser-based XML to JSON converter?
An online XML to JSON converter removes the need to install a command-line tool or write a throwaway script. You paste an XML document, see the JSON immediately, and copy or download the result. Because the conversion runs entirely in your browser, the XML never leaves your machine — useful when the document contains internal configuration, customer-shaped test data, or integration payloads you would not paste into an unknown third-party service.
For JavaScript developers, the same task is often done with a parser library in Node.js or the browser. A ready-made converter is faster for one-off conversions, inspecting a feed, or understanding how a particular XML structure maps to JSON before committing to a mapping in code.
XML ELEMENTS AND JSON PROPERTIES
How XML elements become JSON properties
A simple XML element maps directly to a JSON property whose name is the element name and whose value is the element's text content:
<name>John</name>
becomes:
{ "name": "John" }Nested elements map naturally to nested objects. An element that contains child elements becomes a JSON object, while an element that contains only text becomes a JSON string. This keeps the hierarchy that XML expresses rather than flattening it into a single level.
XML ATTRIBUTES IN JSON
How XML attributes are preserved
XML attributes carry meaningful data — identifiers, types, units, and metadata. Silently dropping them would lose information, so this converter preserves every attribute using the @_ prefix. An attribute id becomes the JSON property @_id.
<item id="001" category="book"> <name>Book</name> </item>
becomes:
{
"item": {
"@_id": "001",
"@_category": "book",
"name": "Book"
}
}The @_ prefix clearly separates attributes from child elements and matches the convention used by the underlying XML parser, so the mapping is predictable and easy to reverse later.
REPEATED XML ELEMENTS AND JSON ARRAYS
How repeated elements become JSON arrays
When the same element appears multiple times at the same level, the converter groups those values into a JSON array. When an element appears only once, it stays a scalar or object. This avoids the common XML-to-JSON mistake of forcing every value into an array, which would make simple documents unnecessarily verbose.
<items> <item>A</item> <item>B</item> </items>
becomes:
{ "items": { "item": ["A", "B"] } }while a single occurrence stays a scalar:
{ "items": { "item": "A" } }This is a critical rule. Forcing single elements into arrays breaks downstream code that expects a string, and ignoring repetition silently drops all but the last value. The deterministic rule here — one occurrence is a value, two or more are an array — keeps both cases predictable.
XML VALUES AND DATA TYPES
Why XML values stay as strings
XML text is text by nature, so this converter keeps element and attribute values as JSON strings by default. A value like 00123 remains the string "00123" rather than the number 123. That distinction matters: identifiers, postal codes, phone numbers, and version strings can have meaningful leading zeros that aggressive type inference would destroy.
Similarly, true and false remain the strings "true" and "false". XML does not have a native boolean type, and a text value that happens to read "true" is not necessarily a boolean. Preserving the text is the safe, lossless default. If a downstream system needs typed values, it can apply its own conversion rules where it knows the intended schema.
No custom date inference is performed. An element containing 2025-01-15 is returned as the string "2025-01-15" so that date parsing stays under your control.
EMPTY XML ELEMENTS
How empty elements are handled
An empty element — written either as <description></description> or as the self-closing <description/> — becomes an empty string rather than being removed:
{ "description": "" }Removing the property entirely would change the shape of the object and hide the fact that the field exists but has no value. Keeping an empty string preserves the field's presence and is deterministic.
XML NAMESPACES
How namespaces are preserved
Namespace prefixes are kept in element names rather than stripped. A SOAP envelope such as <soap:Envelope> is represented with its prefix intact, for example as a soap:Envelope key. Prefixes can be meaningful — they distinguish elements that share a local name but belong to different vocabularies — so removing them could merge unrelated structures. The converter does not silently rewrite or drop namespace prefixes.
XML DECLARATIONS
How the XML declaration is handled
The XML declaration — <?xml version="1.0" encoding="UTF-8"?> — is document metadata, not data. It is ignored rather than turned into a JSON property, so the output JSON represents the actual content of the document. The declared encoding is respected when reading uploaded files as UTF-8 text.
MIXED XML CONTENT
Mixed content limitations
Some XML mixes text with child elements inside the same element, such as a paragraph containing inline markup. JSON has no native way to represent "text plus children" in a single position, so this tool uses the parser's standard representation: child elements become properties and surrounding text is collected under a #text property. When mixed content is detected, a conversion note is shown so you know the standard representation was applied.
Mixed content is inherently lossy when mapped to a plain JSON object, because the exact interleaving of text and elements is not preserved. For documents where the exact order of inline content matters, a dedicated XML processing step is more appropriate than a generic JSON conversion.
PRIVATE LOCAL PROCESSING
Convert XML to JSON without uploading
Your XML is processed locally in your browser and is not uploaded to our servers. There is no account to create, no API key to obtain, and no backend conversion API or large language model involved. XML contents are not placed in URLs and are not sent to external APIs.
This makes the converter suitable for internal configuration files, development fixtures, and integration payloads that should not be pasted into an unknown online service. As with any browser-based tool, local processing is not a substitute for protecting your browser session and your own data policies.
If you need the reverse direction, use the JSON to XML Converter. For human-readable configuration, the JSON to YAML Converter may be a better fit. For spreadsheet workflows, try the JSON to CSV Converter or the JSON to Excel Converter.
TROUBLESHOOTING
Common XML to JSON conversion problems
Malformed XML — a missing closing tag, an unquoted attribute, or mismatched nesting produces an "Invalid XML" error with line and column information when the parser can determine it. The tool does not silently repair malformed XML, because guessing would risk changing your data.
Repeated elements — if a value unexpectedly becomes an array, check whether the source element appears more than once. Conversely, a single occurrence stays a scalar by design.
Attributes — attributes are preserved with the @_ prefix. If you do not see a field you expected as a plain property, check whether it was defined as an attribute rather than a child element.
Namespaces — prefixes such as soap: remain part of the JSON key. Downstream code should account for the colon in property names.
Type conversion — all values remain strings. Convert identifiers and other typed fields yourself only where the schema is known.
Large XML files — very large documents are parsed in memory and may make the browser unresponsive. For files beyond a few megabytes, consider splitting the document or using a local script.
FAQ
Frequently asked questions about XML to JSON
How do I convert XML to JSON?
Paste or upload valid XML, choose 2-space or 4-space indentation, review the JSON preview, then copy or download it.
Can I convert an XML file to JSON?
Yes. Choose or drop a local .xml file. The base filename is reused for the downloaded .json file.
How are XML attributes converted to JSON?
Attributes are preserved as JSON properties with the @_ prefix, so id="001" becomes "@_id": "001".
How are repeated XML elements converted?
Two or more identical elements at the same level become a JSON array. A single occurrence stays a scalar or object.
Are XML values converted to numbers or booleans?
No. Values stay as strings by default so identifiers with leading zeros and text like "true" are not silently changed.
How are empty XML elements handled?
Empty or self-closing elements become an empty string ("") rather than being removed.
Is my XML uploaded to a server?
No. Conversion runs entirely in your browser, and the XML is not sent to any server, API, or language model.
What is the difference between XML and JSON?
XML is a document-oriented markup language with elements and attributes, while JSON is a data-oriented format of objects, arrays, and scalar values. This tool maps XML to an equivalent JSON structure using deterministic rules.
Ready to Try the #1 AI Agent?
EasyClaw is free to get started. Zero setup. Works on Mac & Windows. Control your desktop with AI starting today.