JSON to XML
Converts JSON to well-formed XML. Special characters are escaped automatically.
2sp · UTF-8
Example Conversion
JSON:
json
{
"user": {
"name": "Ravi Mehta",
"age": 28,
"roles": ["admin", "editor"]
}
}XML (root tag: root):
xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<user>
<name>Ravi Mehta</name>
<age>28</age>
<roles>
<item>admin</item>
<item>editor</item>
</roles>
</user>
</root>JSON vs XML — Key Differences
| Feature | JSON | XML |
|---|---|---|
| Readability | Good | Verbose |
| File size | Smaller | Larger |
| Comments | No | Yes |
| Attributes | No | Yes |
| Namespaces | No | Yes |
| Schema | JSON Schema | XSD, DTD |
| Best for | REST APIs | SOAP, RSS, Office |
Special Character Escaping
XML has five reserved characters that must be escaped inside element content. JSONKit handles all escaping automatically:
| Character | Escaped as |
|---|---|
| & | & |
| < | < |
| > | > |
| " | " |
| ' | ' |
When to Use XML
- ▸SOAP web services — Enterprise APIs that use SOAP protocol require XML payloads
- ▸RSS and Atom feeds — All RSS and Atom feed formats are XML-based
- ▸Microsoft Office — DOCX, XLSX and PPTX files are zipped XML documents internally
- ▸Legacy enterprise — Many banking and government systems only accept XML
- ▸SVG graphics — SVG vector graphics are XML — convert JSON shape data to SVG