JSON Toolbox LogoJSONToolbox

XML to JSON Converter

Convert XML data to JSON online in your browser. Paste XML or open an .xml file, choose how attributes and text nodes are represented, and download or copy the formatted JSON output. Repeated elements can be represented as arrays according to the converter's mapping rules.

JSON output will appear here...
All processing happens in your browser. No JSON is sent to our servers.

Key Features

Paste or Open XML

Paste XML directly into the editor or open a .xml file from your device. The input is parsed in the browser before the JSON output is generated.

Copy or Download JSON

Copy the converted JSON to your clipboard or download it as a .json file for use in APIs, scripts, frontend applications, and data-processing workflows.

Configurable Mapping

Choose the JSON indentation, configure the prefix used for XML attributes, and control whether text content is preserved under a dedicated text key.

Attribute Mapping

Represent XML attributes as JSON properties with a configurable prefix such as @ or @_. A prefix helps distinguish attributes from child elements with similar names.

Nested Elements and Repeated Tags

Convert nested XML elements into nested JSON objects and represent repeated sibling elements as arrays where the parser's mapping rules identify them as repeated values.

Text Node Handling

Preserve element text under a dedicated key when an element contains both attributes and text. This helps avoid losing information in mixed XML structures.

Browser-Based Processing

XML parsing and JSON generation happen in your browser. The page does not require an account or upload the XML to a remote conversion service.

How to Use

1

Enter or open XML

Paste a well-formed XML document into the input editor or open a .xml file from your device. You can use an API response, configuration document, or XML export.

2

Choose mapping options

Select the JSON indentation, choose an attribute prefix, and decide whether element text should be preserved under a dedicated text key.

3

Convert the document

Click Convert to JSON to parse the XML tree and generate a JSON representation. If the XML is malformed, review the parser error and correct the source document.

4

Review and export

Check attributes, text values, repeated elements, namespaces, and nested structures in the output. Copy the JSON or download it as a .json file.

Input
<user id="42">
  <name>Alice</name>
  <age>30</age>
</user>
Output
{
  "user": {
    "@id": "42",
    "name": "Alice",
    "age": "30"
  }
}

How to Convert XML to JSON Online

What Does an XML to JSON Converter Do?

An XML to JSON converter parses an XML document and creates a JSON representation of its elements, attributes, text, and repeated structures. This can make XML data easier to inspect and use in JavaScript applications, APIs, scripts, and modern data-processing workflows.

XML and JSON do not have identical data models. XML distinguishes elements, attributes, namespaces, text nodes, comments, processing instructions, ordering, and mixed content, while JSON represents objects, arrays, strings, numbers, booleans, and null. A converter therefore needs mapping conventions, and the result may not be a lossless reproduction of every XML feature.

Common Use Cases

  • API integration: Convert XML responses into JSON for frontend applications or JavaScript-based processing.
  • Legacy system modernization: Use JSON internally while continuing to consume XML from older services.
  • Data inspection: View deeply nested XML as JSON objects and arrays during debugging or development.
  • Configuration conversion: Transform XML configuration data into a JSON structure for a tool or application that accepts JSON.
  • Data migration: Prepare XML records for processing by JSON-based libraries, scripts, or storage systems.

How to Convert XML to JSON

  1. Enter XML: Paste the XML document or open a .xml file.
  2. Choose formatting: Select 2 or 4 spaces for JSON indentation.
  3. Configure attributes: Choose a prefix such as @ or @_ to distinguish XML attributes from child elements.
  4. Choose text handling: Preserve text under a dedicated key when the document contains attributes, child elements, or mixed content.
  5. Convert and inspect: Generate the JSON and check attributes, repeated tags, text values, namespaces, and nested structures.
  6. Copy or download: Copy the JSON or save it as a .json file for later use.

How XML Elements Map to JSON

  • Elements: XML elements commonly become JSON object properties.
  • Nested elements: Child elements commonly become nested JSON objects.
  • Attributes: Attributes can become properties with a prefix such as @id or @_id.
  • Text values: Simple element text may become a string value, while text beside attributes or child nodes may require a key such as #text.
  • Repeated elements: Repeated sibling tags are commonly represented as JSON arrays.
  • CDATA: CDATA content is generally treated as text because JSON has no native CDATA type.

Attributes and Text Nodes

XML permits an element to contain both attributes and text:

<name priority="high">Alice</name>

A common JSON representation is:

{"name":{"@priority":"high","#text":"Alice"}}

The exact keys depend on the converter's configuration. A configurable attribute prefix helps prevent collisions between an attribute and a child element with the same name. A dedicated text key helps preserve text content when a simple string value is not enough.

Repeated Elements and Array Ambiguity

When several sibling elements share the same tag, a converter can represent them as a JSON array:

<items>
  <item>A</item>
  <item>B</item>
</items>

One challenge is the difference between a single element and a repeated element. Some converters return a scalar or object for one occurrence and an array only when multiple occurrences exist. Other converters force selected element names to always use arrays. Check the output shape if your application expects a stable schema.

Namespaces, CDATA, and Mixed Content

XML namespaces do not have a direct JSON equivalent. A converter may preserve prefixes in property names, remove prefixes, or expose namespace declarations separately. CDATA markers are usually removed while their content is retained as text. Mixed content, where text appears between child elements, can be difficult to represent without preserving order explicitly.

For SOAP, SVG, SAML, RSS, Atom, or other namespace-heavy documents, test a representative sample and verify that the output retains the information your application actually needs.

XML to JSON Is Not Always Reversible

Converting XML to JSON and then converting the result back to XML may produce a structurally similar document, but not necessarily the original document. Comments, whitespace, attribute order, namespace declarations, CDATA markers, document formatting, and mixed-content order may change or disappear. Keep the original XML if exact reconstruction matters.

Common XML Conversion Errors

  • Unclosed tags: Every opening element must have a matching closing element unless it is self-closing.
  • Invalid nesting: XML elements must be properly nested.
  • Unescaped ampersands: A literal ampersand in text usually needs to be written as &amp;.
  • Malformed attributes: Attribute values need valid quotation marks.
  • Unexpected namespaces: Namespace declarations and prefixes may affect the output keys.
  • Unstable arrays: A single repeated-element occurrence may produce a different JSON shape from multiple occurrences.

Browser-Based Privacy

This converter is designed to parse XML and generate JSON in the browser instead of sending the source document to a remote conversion service. That can be useful for development data and private integration samples. It is not a substitute for secure secret management, so avoid entering credentials, tokens, private customer information, or production secrets into any online converter.

When to Use a Local XML Tool

A browser-based converter is convenient for one-off transformations and inspection. For repeatable automation, very large files, confidential documents, CI pipelines, or strict schema requirements, use a trusted local library or command-line tool and define the XML-to-JSON mapping explicitly.

Related Tools

Frequently Asked Questions

Is XML to JSON conversion lossless?

Not always. XML and JSON have different data models, so attributes, namespaces, mixed content, comments, processing instructions, ordering, and some type information may require conventions or may not be preserved exactly. Review the output before using it downstream.

How are XML attributes represented?

Attributes are represented as JSON properties using the configured prefix, such as @id or @_id. The prefix helps distinguish an XML attribute from a child element with the same name.

What does Preserve text nodes do?

When enabled, text content can be stored under a dedicated key such as #text when an element also contains attributes or child structures. This helps preserve text that would otherwise be difficult to represent alongside attributes.

How are repeated XML elements handled?

Repeated sibling elements with the same tag name are commonly represented as a JSON array. A single occurrence may remain a scalar or object, depending on the parser's mapping rules.

Can I customize the attribute prefix?

Yes, if the option is available in the interface. Common conventions include @ and @_. Choose a prefix that does not conflict with the element names expected by your downstream application.

Does it support XML namespaces?

Basic namespace-qualified XML may parse, but namespace handling depends on the parser and mapping implementation. Prefixes may remain in element names, be removed, or require additional processing. Do not assume that a converted namespace has the same meaning as it had in the original XML.

Does it support CDATA sections?

Many XML parsers expose CDATA content as text, but the exact output depends on the parser. CDATA markers are usually not preserved as a separate JSON type because JSON has no direct CDATA equivalent.

Can I convert SOAP XML to JSON?

You may be able to convert a well-formed SOAP envelope as XML, but the result is only a structural representation. It does not automatically convert SOAP operations, namespaces, schemas, authentication, or service-specific semantics into a REST-style JSON API.

Can I convert JSON back to XML?

Use a separate JSON to XML converter for the reverse direction. A JSON representation may not contain enough information to reconstruct the original XML exactly, especially when attributes, namespaces, ordering, mixed content, or comments were not preserved.

Can I convert a large XML file?

The practical limit depends on browser memory, device performance, XML depth, number of elements, and parser behavior. Large XML files may take longer to parse and may require substantial memory because the document is loaded in the browser.

Why does my XML fail to convert?

Common causes include an unclosed tag, mismatched element names, invalid nesting, malformed attributes, an invalid declaration, unescaped ampersands, or incomplete XML. Check the reported location and validate the source document before trying again.

Is my XML uploaded to a server?

This page is designed to parse XML and generate JSON in your browser without requiring a server upload. You should still avoid entering passwords, API keys, access tokens, private customer data, or confidential production XML into any browser-based tool.

Is this a free XML to JSON converter?

Yes. You can paste or open XML, configure the available mapping options, and copy or download the JSON output without creating an account.