JSON
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format that stores information as key–value pairs and ordered lists. Although its syntax originates from JavaScript object literals, it is entirely language-independent and supported almost everywhere. Its strength is simplicity: JSON files are both human-readable and lightning-fast for machines to parse, which is why they have become the default language for communication in modern web applications.
How JSON syntax works
JSON is built from two container types and a few primitive types:
- object — a pair of curly braces { } holding key–value pairs, e.g. {"name": "server1", "active": true};
- array — square brackets [ ] grouping an ordered list of values;
- primitive values — strings in double quotes, numbers, booleans (true/false) and null.
Keys are always text, and structures can be nested arbitrarily to build complex data trees. The format itself stores no comments and has no dedicated date type — dates must be encoded as strings according to an agreed convention.
Practical application
The most common use of JSON is communication over a REST API: a front-end app sends a request and the server responds with a JSON payload that the browser turns straight into an object. The same format carries webhook payloads and the responses of many hosting and cloud services.
Beyond data exchange, JSON is excellent for configuration — files such as package.json and composer.json describe a project's dependencies in exactly this format. Document databases like MongoDB store records in a JSON-like structure, and application logs are increasingly written as JSON lines so they can be indexed and searched easily. A popular variant is JSON-LD, used to embed structured data in web pages.
Powiązane pojęcia
Najczęstsze pytania
How is JSON different from XML?
Both formats exchange data, but JSON is usually more compact and faster to parse because it needs no closing tags. XML, on the other hand, supports attributes, namespaces and validation schemas, so it's often chosen where rich structure and formal document validation matter.
