JSON to XML
Paste a JSON document and get back the XML equivalent with the name of the root element you choose, a consistent strategy for arrays (repeated elements or a wrapper), optional XML declaration and pretty indentation. Useful when a legacy system demands XML and your upstream data lives as JSON.
How to convert JSON to XML
-
1
Paste JSON
Object or array at the top level. You will give the root element a name.
-
2
Name the root
XML requires a single root element. Default is `<root>`; give it something meaningful like `<users>` or `<response>`.
-
3
Pick array strategy
"Repeated elements" (each array item becomes a sibling `<item>`) or "wrapper" (the array goes inside a named wrapper element).
-
4
Copy the XML
Optional XML declaration, proper indentation, and entity-escaped values for `<`, `>`, `&` and quotes.
Example: repeated elements
Input:
{ "users": [ { "name": "Alice" }, { "name": "Bob" } ] }
Output:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<users>
<name>Alice</name>
</users>
<users>
<name>Bob</name>
</users>
</root>
Example: array wrapper
Same input with the “wrap arrays in <item>” strategy:
<root>
<users>
<item>
<name>Alice</name>
</item>
<item>
<name>Bob</name>
</item>
</users>
</root>
Type mapping
| JSON | XML |
|---|---|
| string | text content, entity-escaped |
| integer / decimal | text content (no XML type annotation) |
| boolean | true / false as text |
| null | empty element (<foo/>) or omitted |
| array | repeated elements or wrapper + items |
| object | nested element with child elements |
Attributes vs elements
XML distinguishes attributes (<user id="1">) from child elements (<user><id>1</id></user>). The converter defaults to elements, they are lossless for round-tripping. If your downstream XML requires attributes, use a key prefix convention:
- JSON key
@idbecomes an XML attributeid="..."on the parent element. - JSON key
#textbecomes the text content of the parent element.
These conventions come from BadgerFish and Parker mappings, the two most common JSON-to-XML standards.
Escaping rules
<-><>->>&->&"->"(in attribute values)'->'(optional)- Bytes in UTF-8 are preserved, declared in the XML prolog.
Common mistakes
- Root-level JSON array. XML needs a single root element. The converter wraps an array in
<root>(or whatever name you choose). - Numeric keys. JSON
{"1": "a"}is legal; XML element names cannot start with a digit. The converter prefixes digits with an underscore (_1) or lets you define a custom mapping. - Mixed arrays.
[1, "two", { "x": true }]has no clean mapping. Usually this means the JSON needs normalization before conversion. - Huge documents. XML is verbose, a 10 MB JSON can become a 20-30 MB XML. Consider streaming conversion for very large payloads.
Frequently Asked Questions
XML requires a single root by specification. If your JSON is an array or has multiple top-level keys, the converter wraps everything in a root element you can name (default <root>).
Yes. Use the @-prefix convention in your JSON keys (e.g. "@id": 1) and those keys become attributes. Other keys stay as child elements. This matches the BadgerFish mapping.
Two strategies: repeated sibling elements (each item gets the parent key as its tag), or a wrapper with <item> elements inside. Pick whichever matches the XML schema you are targeting.
No. The converter emits the XML declaration (<?xml version="1.0"?>) but not a DOCTYPE. For XML that needs a DTD or XSD reference, add it manually after conversion.
Related Tools
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.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
JSON Formatter
Paste JSON to pretty-print with 2 or 4 spaces, minify it to compact output, or run a quick syntax check before copying the result.
Tool available in other languages
- JSON vers XML [FR]
- JSON till XML [SV]
- แปลง JSON เป็น XML [TH]
- JSON إلى XML [AR]
- JSON ke XML [ID]
- Chuyển đổi từ JSON sang XML [VI]
- JSON에서 XML로 [KO]
- JSON zu XML [DE]
- JSON a XML [ES]
- JSON naar XML [NL]
- JSON do XML [PL]
- JSONからXMLへ [JA]
- JSON para XML [PT]
- Преобразование JSON в XML [RU]
- JSON'ten XML'e [TR]
- JSON 到 XML [ZH]
- JSON in XML [IT]