JSON (JavaScript Object Notation) and XML (eXtensible Markup Language) are both text formats for structured data. They differ in syntax, verbosity, schema ecosystems, and where each is still the default choice.
This guide compares them at a high level, shows the same logical record in both formats, and outlines readability, usage, and parsing trade‑offs.
JSON (JavaScript Object Notation)
JSON is a minimal, language‑independent format derived from JavaScript literal syntax. It is the dominant choice for REST and GraphQL payloads, browser fetch, and many mobile clients because it maps cleanly to objects and arrays in modern languages.
Simplicity
Objects { }, arrays [ ], strings, numbers, booleans, and null cover almost every API contract.
Compactness
Same data is usually smaller on the wire than verbose XML with repeated tag names.
JavaScript & web fit
JSON.parse / JSON.stringify are built into browsers and Node.js; other stacks ship fast native parsers.
XML (eXtensible Markup Language)
XML describes tree‑shaped data with nested elements, optional attributes, and namespaces. It is still common in enterprise integration, SOAP, configuration (for example Spring XML), RSS/Atom, and document formats where mixed content matters.
Hierarchical structure
Clear parent/child boundaries; attributes hang on elements without extra nesting.
Extensibility
Vocabularies combine via namespaces; XSD and related tooling mature in regulated industries.
Wide adoption
Long history in B2B, publishing, and standards bodies—interop with legacy systems is a strength.
Syntax comparison
Below is one small person record expressed as JSON and as XML. In XML, false is plain text inside the element; your schema or code decides how to interpret it.
JSON has no built‑in attributes or namespaces; everything is keys and values in a tree. XML can attach metadata on tags (id=, xmlns:) and is still common where schemas, signatures, and enterprise tooling expect angle‑bracket documents.