What is JSON? Complete Guide with Examples
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. Despite its name, JSON is language-independent and supported by virtually every programming language. It uses key-value pairs and ordered lists to represent structured data, making it the dominant format for web APIs, configuration files, and data storage.
How Does JSON Work?
JSON represents data using two structures: objects (unordered collections of key-value pairs enclosed in curly braces) and arrays (ordered lists of values enclosed in square brackets). Keys must be double-quoted strings. Values can be strings, numbers, booleans (true/false), null, objects, or arrays. JSON parsing converts the text representation into native data structures (dictionaries, lists) in the target programming language. JSON.parse() and JSON.stringify() in JavaScript handle this conversion.
Key Features
- Six data types: string, number, boolean, null, object, and array
- Human-readable text format with simple syntax rules
- Native support in JavaScript and built-in parsers in all major languages
- Lightweight compared to XML — no closing tags, attributes, or namespaces
- Strict syntax that prevents ambiguity (double quotes required, no trailing commas, no comments)
Common Use Cases
REST API Communication
JSON is the standard format for request and response bodies in REST APIs. Frontend applications send JSON payloads to servers and parse JSON responses to display data.
Configuration Files
Package managers (package.json), TypeScript (tsconfig.json), and many tools use JSON for configuration because it's structured, parseable, and widely supported.
Data Storage and Caching
NoSQL databases like MongoDB store documents as JSON (BSON). Redis and browser localStorage use JSON serialization for caching structured data.