JSON GUIDE · 3 MIN READ

JSON vs XML: choose a mapping deliberately

Compare records with XML documents and understand why conversion is often lossy.

Different structures solve different problems

JSON works naturally for records, lists, and scalar values. XML has elements, attributes, namespaces, and text that can appear between child elements. A document with emphasized words inside a paragraph has a structure that does not fit a simple object-to-element rule.

Choose based on the receiving system's contract. A JSON API is usually easiest to use as JSON; an XML service may require particular names, namespace declarations, and element ordering. Smaller syntax alone does not decide interoperability.

<person active="true"><name>Ada</name><tag>editor</tag><tag>author</tag></person>

Review converted data before using it

When converting, decide how attributes and text are represented, how repeated elements become arrays, and what a single occurrence means. XML does not automatically distinguish a numeric-looking string from a number or an empty element from a JSON null.

Round-trip a representative sample before building an automated pipeline. Include repeated and singleton children, empty values, Unicode, and mixed text. JSONSlate rejects document type declarations and external entities; it does not fetch resources referenced by untrusted XML.

Put it into practice

Further reading

← All JSON guides