Output will appear here
Output will appear here
Paste an XML document and get JSON keyed by element name, starting with the root tag. Attributes are collected under @attributes. When the same child tag appears more than once it becomes an array, but a single child stays an object. All text values are strings. The XML declaration, DOCTYPE and comments are skipped.
By Ankit Aglawe · Updated · Runs entirely in your browser
Two <item> tags become an array. <guid> has both an attribute and text, so it becomes an object with @attributes and #text. The version attribute on <rss> lands in @attributes too.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Acme Engineering</title>
<link>https://acme.dev/blog</link>
<item>
<title>Moving to Postgres 16</title>
<guid isPermaLink="false">post-41</guid>
<pubDate>Tue, 05 Mar 2024 09:00:00 GMT</pubDate>
</item>
<item>
<title>Our on-call rota</title>
<guid isPermaLink="false">post-42</guid>
<pubDate>Fri, 15 Mar 2024 09:00:00 GMT</pubDate>
</item>
</channel>
</rss>{
"rss": {
"@attributes": {
"version": "2.0"
},
"channel": {
"title": "Acme Engineering",
"link": "https://acme.dev/blog",
"item": [
{
"title": "Moving to Postgres 16",
"guid": {
"@attributes": {
"isPermaLink": "false"
},
"#text": "post-41"
},
"pubDate": "Tue, 05 Mar 2024 09:00:00 GMT"
},
{
"title": "Our on-call rota",
"guid": {
"@attributes": {
"isPermaLink": "false"
},
"#text": "post-42"
},
"pubDate": "Fri, 15 Mar 2024 09:00:00 GMT"
}
]
}
}
}There is only one <dependency>, so it is an object, not a one-item array. Add a second dependency and it becomes an array. Code reading this JSON should handle both shapes. The xmlns declaration is kept as an ordinary attribute.
<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>com.acme</groupId>
<artifactId>billing</artifactId>
<version>1.4.0</version>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>{
"project": {
"@attributes": {
"xmlns": "http://maven.apache.org/POM/4.0.0"
},
"groupId": "com.acme",
"artifactId": "billing",
"version": "1.4.0",
"dependencies": {
"dependency": {
"groupId": "org.postgresql",
"artifactId": "postgresql",
"version": "42.7.3",
"scope": "runtime"
}
}
}
}Arrays are created only when a tag repeats under the same parent. <tags><tag>a</tag></tags> gives {"tag": "a"}, while two <tag> children give ["a", "b"]. Normalize with something like [].concat(x) in your code.
Attributes go into an @attributes object. A self-closing tag with attributes, like <img src="a.png"/>, becomes {"@attributes": {"src": "a.png"}}. Attribute values are always strings.
An element with attributes and text, like <price currency="USD">44.95</price>, becomes an object with @attributes and #text. Without attributes, the same element is just the string "44.95".
Prefixes are kept as part of the key, so <dc:title> becomes "dc:title". xmlns and xmlns:dc declarations appear in @attributes. Namespace URIs are not resolved.
No type guessing: <qty>2</qty> gives "2" and <paid>true</paid> gives "true". Empty elements, <a/> or <a></a>, give null. Whitespace around text is trimmed.
Children are grouped by name, so <x/><y/><x/> loses the original interleaving. In mixed content like Hello <b>world</b>, the text pieces are joined into #text and the element goes under its own key.
CDATA content is copied as-is, so HTML inside it stays readable. The five named entities (&, <, >, ", ') and numeric references like © and 😀 are decoded, once, so &lt; gives <. Other named entities from a DTD, like , are left as written. Malformed XML, such as a mismatched closing tag, stops with a line and column number.
| XML | JSON | Notes |
|---|---|---|
<a>text</a> | "a": "text" | Always a string |
<a/> | "a": null | |
<a id="1"/> | {"@attributes": {"id": "1"}} | |
<a id="1">t</a> | {"@attributes": {...}, "#text": "t"} | |
two <b> in <a> | "b": [..., ...] | Array only when repeated |
one <b> in <a> | "b": {...} or "b": "..." | Not an array |
<dc:title> | "dc:title" | Prefix kept |
<![CDATA[<b>x</b>]]> | "<b>x</b>" | Raw text |
Enter well-formed XML into the input editor. The converter handles elements, attributes, namespaces, CDATA sections, and mixed content nodes.
The right pane displays the converted JSON with XML elements mapped to objects, attributes prefixed with @, and text content stored in #text keys. Arrays are created for repeated sibling elements.
Click Copy to grab the JSON output or download it as a .json file. The output is valid JSON ready to be consumed by any API, database, or JavaScript application.
Paste the XML in the left pane. The JSON appears on the right, with the root element as the single top-level key.
Under an @attributes key on the element, as a map of name to string value. Element text then goes under #text.
XML does not say whether an element is a list. The converter only makes an array when it sees a tag repeat. If your code expects a list, wrap the value when it is not already an array.
No. Every text value stays a string, because XML text has no types and guessing could change ids or zip codes.
Yes, it parses it. Prefixed names like soap:Envelope stay as keys, and xmlns declarations show up as attributes.
No. Parsing runs locally on the page.
Need several formats at once? Convert All shows every output from one paste. Or browse all JSON converters.