What is JSON?
.json · application/json
JSON (JavaScript Object Notation) is a lightweight, human-readable data interchange format used universally in web APIs, configuration files, and data storage.
Overview
JSON (JavaScript Object Notation) is a text-based data interchange format derived from JavaScript object literal syntax. Despite its origins in JavaScript, JSON is language-independent and supported by virtually every modern programming language. It has become the dominant format for web APIs, replacing XML in most use cases due to its simplicity and smaller payload size. JSON supports six data types: strings, numbers, booleans, null, arrays, and objects.
History
JSON was specified by Douglas Crockford in the early 2000s. He didn't invent a new format but rather identified and documented a useful subset of JavaScript that was already being used for data interchange. The format was first standardized as ECMA-404 in 2013 and as RFC 7159 (later superseded by RFC 8259) by the IETF. Its simplicity and readability led to rapid adoption, largely replacing XML for web API communication.
File Structure
A JSON document is built from two structures: objects (unordered collections of key-value pairs enclosed in curly braces) and arrays (ordered lists of values enclosed in square brackets). Values can be strings (double-quoted), numbers, booleans (true/false), null, objects, or arrays. Keys must be strings. The entire document must be valid UTF-8 encoded text.
Common Use Cases
- REST API request and response payloads
- Application configuration files
- NoSQL database storage (MongoDB, CouchDB)
- Data exchange between services
- Package manifests (package.json, composer.json)
- Web application state management
- Logging and event data
- Schema definitions (JSON Schema)
Advantages
- Human-readable and easy to write
- Lightweight with minimal syntax overhead
- Native support in JavaScript/browsers
- Universal language support
- Faster parsing than XML
- Simple, well-defined specification
Disadvantages
- No comment support in standard JSON
- No date/time native data type
- No support for binary data
- Limited number precision (IEEE 754)
- No schema enforcement by default
- Trailing commas not allowed
Frequently Asked Questions
What is a JSON file?
A JSON (JavaScript Object Notation) file is a text file that stores data in a structured, human-readable format using key-value pairs and arrays. It's the most common format for web APIs and configuration files.
How do I open a JSON file?
JSON files can be opened with any text editor (VS Code, Notepad++, Sublime Text), web browsers, or specialized JSON viewers. Most code editors provide syntax highlighting and formatting for JSON.
What is the difference between JSON and XML?
JSON is lighter, easier to read, and faster to parse than XML. XML supports attributes, comments, and namespaces which JSON lacks. JSON is preferred for web APIs while XML is still used in enterprise systems, SOAP services, and document formats.
Can JSON have comments?
Standard JSON (RFC 8259) does not support comments. However, JSON5 and JSONC (JSON with Comments) are extensions that allow comments. Many tools like VS Code support JSONC for configuration files.
Technical Details
- Extension
- .json
- MIME Type
- application/json
- Magic Bytes
- None (text-based)
- Encoding
- UTF-8 (required by RFC 8259)
- Compression
- None (use gzip for transport)
- Specification
- RFC 8259 / ECMA-404
- Max Size
- No specification limit