Last modified: March 23, 2026
This article is written in: 🇺🇸
JSON, or JavaScript Object Notation, is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. Despite originating from JavaScript, the format is completely language independent and supported by virtually every modern programming language. Its simplicity and direct mapping to common data structures like hash maps and arrays have made it the dominant format for APIs, configuration files, and data exchange on the web.
+----- JSON Document ----------------------------------------+
| |
| { |
| "key": "string value", <-- String |
| "count": 42, <-- Number |
| "active": true, <-- Boolean |
| "tags": ["a", "b"], <-- Array |
| "nested": { ... }, <-- Object |
| "empty": null <-- Null |
| } |
| |
+------------------------------------------------------------+
JSON defines six primitive value types that combine to represent nearly any data structure:
\n and \uXXXX.true or false.{}, where every key must be a string.[], and its elements can be of any type including mixed types."name": "John").{} and arrays in square brackets []._comment keys or JSON5 extensions exist as workarounds.Here is a JSON document showing nested objects, arrays, and multiple data types working together:
{
"employee": {
"name": "John Doe",
"age": 30,
"active": true,
"department": "Engineering",
"address": {
"street": "1234 Main St",
"city": "Anytown",
"state": "CA",
"zipCode": "12345"
},
"skills": ["Java", "C#", "Python"],
"certifications": null
}
}
When a backend service receives a JSON payload, the text goes through a well-defined parsing pipeline before the application can use the data:
Raw bytes Decode to Tokenize Build AST / Application
from network --> UTF-8 text --> (lexer) -------> data structure --> logic
| |
Split into tokens: Map to native
{ , } , [ , ] , types (dict,
"key", : , value list, int, str)
json module or popular libraries like Jackson (Java), serde_json (Rust), or encoding/json (Go).JSON Schema is a vocabulary that lets you annotate and validate the structure of JSON documents. It acts like a contract between producers and consumers of an API.
JSON Document JSON Schema
+------------------+ +---------------------------+
| { | validate | { |
| "age": 30 | ----------> | "type": "object", |
| } | against | "properties": { |
+------------------+ | "age": { |
| | "type": "integer", |
v | "minimum": 0 |
Valid / Invalid | } |
| }, |
| "required": ["age"] |
| } |
+---------------------------+
required keyword lists fields that must be present in a valid document.minimum, maxLength, and pattern enforce bounds on individual values.$ref keyword allows schemas to reference reusable definitions, keeping large schemas maintainable.Standard JSON requires loading the entire document into memory before parsing, which is problematic for large datasets. Newline-Delimited JSON (NDJSON), also called JSON Lines, solves this by placing one valid JSON object per line:
{"event": "click", "ts": 1700000001}
{"event": "view", "ts": 1700000002}
{"event": "click", "ts": 1700000003}
jq, grep, or awk process records line by line.9007199254740993 may lose precision silently."id": "9007199254740993") and parse them explicitly.\u0000 (null byte) can break parsers or cause security issues in some languages.\uD83D\uDE00).ijson in Python) keep memory usage constant for large documents.Both JSON and XML are text-based data interchange formats, but they serve different niches. JSON dominates in web APIs and microservices, while XML remains common in enterprise systems, document markup, and contexts that require schemas with namespaces.
| Feature | JSON (JavaScript Object Notation) | XML (eXtensible Markup Language) |
| Format | Lightweight and text-based. | Verbose and document-based format. |
| Readability | Generally easier to read due to its concise format. | Less human-readable due to more verbose nature. |
| Data Types | Supports string, number, array, boolean, object, and null. | Does not have built-in data types; everything is a string. |
| Parsing | Native support in browsers; fast parsers in every language. | Requires dedicated XML parsers (DOM, SAX, StAX). |
| Size | Typically smaller, making it faster to transmit. | Larger file sizes due to additional markup and closing tags. |
| Schema Validation | JSON Schema (draft standard, widely adopted). | XSD and DTD (mature, W3C standards). |
| Extensibility | Limited; fixed structure of objects and arrays. | Highly extensible with custom tags, namespaces, and attributes. |
| Metadata | Limited support; metadata mixed into the data structure. | Excellent support via attributes and processing instructions. |
| Comments | Does not support comments natively. | Supports comments with <!-- --> syntax. |
| Security | Less attack surface; no entity expansion vulnerabilities. | Prone to XXE (XML External Entity) and billion-laughs attacks. |
| Array Support | First-class arrays with square brackets []. |
No built-in array; relies on repeated child elements. |
| Namespace Support | No namespace mechanism. | Full namespace support for avoiding naming collisions. |
| Use Cases | Web APIs, microservices, configuration files, mobile apps. | Enterprise integrations (SOAP), document markup, RSS/Atom feeds. |
createdAt over ca).null over missing keys when a field has no value, so consumers can distinguish "absent" from "not provided".