Logo JSON Parser Online

Convert XML to JSON Online

Paste XML and click Convert. The tool parses your XML using the browser's built-in DOMParser and produces a JSON object that mirrors the element structure. Attributes, text content, and nested elements are all represented in the output.

All JSON Tools

28 tools

Free, fast, runs in your browser. No login needed.

Made with ❤️ in India · © 2025 parsejsononline.com
INPUT
1
OUTPUT
1
✅ Ready
Characters: 0
Ctrl+Enter to run
What is this tool?

How to use

  1. Paste your XML into the INPUT pane.
  2. Click Convert.
  3. The output is a JSON object representing the XML structure, formatted with 2-space indentation.
  4. Copy or download the result.

How it works

The converter uses the browser's native DOMParser to parse XML, then recursively converts the DOM tree to a JSON object using these rules:

  • Element with only text content — the element becomes a string value: <name>Alice</name> → "name": "Alice".
  • Element with child elements — becomes an object with the child tag names as keys.
  • Attributes — stored under the special "@" key as an object: <item id="1"> → {"@": {"id": "1"}, ...}.
  • Repeated sibling elements — if the same tag name appears more than once, the values are automatically collected into an array.

Namespaces. Namespace prefixes become part of the key name as-is. For example, <ns:item> produces the key "ns:item". Namespace declarations (xmlns attributes) appear under the "@" key.

Mixed content. If an element contains both text and child elements, the text node content is assigned directly to the object (overwriting it). This is an edge case — avoid XML with mixed content for best results.

Common use cases: converting API responses or data feeds from XML to JSON for use in JavaScript applications; migrating XML config files to JSON; inspecting XML structure in a more readable format.

FAQ

How are XML attributes represented in the JSON?

Attributes are collected under a special "@" key as an object. For example, becomes {"@": {"id": "1", "type": "foo"}} alongside any child element keys.

What happens with repeated elements like appearing multiple times?

The first occurrence creates a single value. When the same tag name appears a second time under the same parent, the values are automatically merged into an array. All subsequent occurrences are pushed onto that array.

Does it handle XML namespaces?

Namespace prefixes are preserved as part of the key name (e.g., "ns:item"). Namespace URI declarations appear as attributes under the "@" key. Namespace-aware merging is not performed.

Can I convert back from JSON to XML?

Yes. Use the JSON to XML tool on this site. Note that the "@" attribute convention and array-to-siblings mapping are the reverse of what JSON to XML produces.

Is my data sent anywhere?

No. Parsing runs entirely in your browser using the native DOMParser.

Related tools

JSON to XMLConvert JSON back to XML structure. JSON FormatterFormat the converted JSON output. JSON ValidatorValidate the JSON after conversion.