XML to JSON
XML and JSON model data differently: XML has attributes and mixed content, JSON has objects and arrays. Converting without loss needs a convention. This tool offers three: compact (drops attributes), Badgerfish (attributes under @key, text under $) and literal (every XML node becomes a JSON object with full fidelity). Pick the one that matches the JSON consumer you are targeting.
How to convert XML to JSON
-
1
Paste XML
Any well-formed XML. Namespaces are preserved.
-
2
Pick conversion style
Compact, Badgerfish or literal/lossless.
-
3
Handle arrays
Force certain elements to always be arrays (configurable).
-
4
Copy JSON output
Pretty-printed or minified, your choice.
The three styles compared
Input:
<book id="1" lang="en">
<title>1984</title>
<author>Orwell</author>
</book>
Compact (drops attributes):
{
"book": {
"title": "1984",
"author": "Orwell"
}
}
Badgerfish (attributes under @, text under $):
{
"book": {
"@id": "1",
"@lang": "en",
"title": { "$": "1984" },
"author": { "$": "Orwell" }
}
}
Literal / JsonML-ish (full fidelity):
{
"book": {
"@attributes": { "id": "1", "lang": "en" },
"title": "1984",
"author": "Orwell"
}
}
Forced arrays
XML has no way to say “this is a list of one”. A single-element sequence looks identical to a scalar:
<items>
<item>A</item>
</items>
That can serialise as either {"item": "A"} or {"item": ["A"]}. The converter lets you mark element names (by XPath) as always-arrays, so your downstream JSON consumer gets consistent types.
Mixed content
Mixed content, text interleaved with child elements, is the one place where any XML-to-JSON conversion loses information:
<p>Hello <em>world</em>!</p>
Most styles either drop text or collapse it. The literal style preserves order via an array:
{
"p": {
"@content": ["Hello ", { "em": "world" }, "!"]
}
}
Type inference
By default values are strings. Toggle “parse numeric/boolean” and the converter will cast 42, 3.14, true, false to the matching JSON types. Be careful: an XML attribute id="007" becomes 7 with casting on, which you probably do not want.
When to pick which
- Compact: for human-readable JSON where attributes are noise.
- Badgerfish: when you need attributes and text at the same depth as children.
- Literal: when you must round-trip back to XML without loss.
Frequently Asked Questions
When an element appears once, the converter defaults to object; twice or more, array. Use the force-array option to make it consistent if your consumer expects one shape.
Namespace prefixes are preserved in keys (ns:title) unless you enable “strip namespaces”. The declarations themselves become @xmlns:ns attributes on the root element.
Literal mode is the closest to lossless but mixed content ordering between elements and text is tricky. Compact mode definitely loses attributes. Badgerfish is a pragmatic middle ground.
No. Conversion runs in your browser.
Related Tools
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
Color Wheel Explorer
Explore the colour wheel interactively. Rotate harmonies, compare HSL vs RYB, spot complementary and triadic pairs in real time.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
Keyboard Shortcut Reference
Search documented default keyboard shortcuts for VS Code, Chrome and Bash with GNU Readline on macOS, Windows and Linux.
Tool available in other languages
- XML zu JSON [DE]
- XML para JSON [PT]
- Chuyển đổi từ XML sang JSON [VI]
- XML till JSON [SV]
- แปลง XML เป็น JSON [TH]
- XML ke JSON [ID]
- XML → JSON [KO]
- XML a JSON [ES]
- XMLからJSONへ [JA]
- XML إلى JSON [AR]
- XML vers JSON [FR]
- XML naar JSON [NL]
- XML do JSON [PL]
- XML in JSON [IT]
- От XML к JSON [RU]
- XML'den JSON'a [TR]
- XML 转 JSON [ZH]