Learn

What Is JSON? Definition, Syntax & Examples

JSON (JavaScript Object Notation) is a lightweight, text-based data format used for APIs, configuration files, and data exchange. Defined by ECMA-404 and RFC 8259, JSON supports objects, arrays, strings, numbers, booleans, and null.

JSON Syntax Rules

Objects use curly braces {} with double-quoted keys. Arrays use square brackets []. Strings must use double quotes. Numbers can be integers or decimals. Booleans are true or false. null represents empty values. No trailing commas, comments, or single quotes are allowed.

Example JSON Object

{"name": "Alice", "age": 30, "active": true, "roles": ["admin", "user"]}

Where JSON Is Used

REST and GraphQL APIs, package.json and tsconfig.json, NoSQL databases like MongoDB, AWS CloudFormation templates, Kubernetes manifests, CI/CD pipeline configs, and browser localStorage serialization.

Frequently Asked Questions

Is JSON the same as a JavaScript object?

No. JSON is a text format with stricter rules. JavaScript objects allow unquoted keys, trailing commas, single quotes, undefined, functions, and comments — none of which are valid JSON.

What is the difference between JSON and XML?

JSON is more compact and maps naturally to programming language data structures. XML is more verbose but supports attributes, namespaces, and schemas. JSON dominates modern web APIs.