XML to JSON
Convert XML into JSON: configurable attribute prefix and text key, array strategy for repeated tags, indentation, attribute+text handling, CDATA and comments — with line/column reporting for invalid XML.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Attributes are emitted as @name; repeated child tag names are merged into arrays.
Options
Statistics
Converted JSON
{
"catalog": {
"book": [
{
"@id": "1",
"@lang": "zh",
"title": "工具站",
"price": "39.9",
"tags": {
"tag": [
"工具",
"前端"
]
}
},
{
"@id": "2",
"title": "UniKit <guide>",
"price": "0"
}
]
}
}What this tool does
- Turn SOAP, RSS or legacy API responses into JSON you can drop straight into frontend code or a NoSQL store without writing a parser.
- Skip the manual mapping: attributes become @name and repeated tags merge into arrays automatically, so the hierarchy is obvious at a glance.
- Need an exact match? Turn type inference off and every value stays a string, so identifiers like "0012" are not silently changed to 12.
- Decide per option whether CDATA and comments survive (#cdata / #comment), which helps when auditing what a payload really contains.
Example
Input
<catalog><book id="1"><title>UniKit</title><tag>json</tag><tag>xml</tag></book></catalog>
Output
{
"catalog": {
"book": {
"@id": "1",
"title": "UniKit",
"tag": [
"json",
"xml"
]
}
}
}Output with the default options (attribute prefix @, arrays only for repeated tags, 2-space indent). Type inference is off by default, so @id stays the string "1"; enable it and it becomes the number 1.
Frequently asked questions
Where do attributes and text end up?
Attributes are emitted as @name by default — you can change the prefix, or set a group key to collect them into one object. When an element has attributes or children, its direct text goes into the #text key; an element holding only text collapses to the bare value.
When does a repeated tag become an array?
In the default Auto mode, two or more sibling tags with the same name merge into an array and a single occurrence stays an object. Always array makes every tag an array (handy when an API always returns lists), while Never array keeps only the last occurrence and drops the earlier ones.
Are numbers and booleans converted automatically?
Only when type inference is enabled: text like 123, -1 or 39.9 becomes a number and true / false become booleans. It is off by default because order numbers, phone numbers and version strings lose leading zeros or precision once they become numbers.
How are CDATA and comments handled?
CDATA is merged into the text by default, exactly like ordinary text; enabling the #cdata option keeps it separately under the #cdata key. Comments are dropped by default, and with the keep-comments option they land under #comment, as an array when there are several.
What if the XML is invalid, and is my content uploaded?
Parsing failures report an error code, line and column plus a snippet of the offending line (mismatched-close-tag, unclosed-tag and so on) so you can jump straight to it. All parsing runs locally in your browser, the page makes no network requests, and your XML is never uploaded or logged.
Keywords:xmljsonxml to jsonXML 转 JSON属性CDATA转换serialize