How it works

JSON is a text format for representing data, based on a simple key-value pair syntax. It organizes data in objects, with keys between braces, and arrays, which are lists between brackets. Values can be strings, numbers, booleans, nulls, arrays or other objects. This format does not accept comments or functions, only pure data, and is read by simple libraries in almost every programming language. Because it is lightweight and has no unnecessary markup, JSON has gained ground over older formats in client-server communications. A string in JSON must use double quotes and cannot contain unescaped line breaks. Numbers can be in decimal or scientific notation, and the null value is represented by the word null, without quotes. Common syntax errors include forgetting quotes on keys, using single quotes in strings or placing a comma after the last item in an object.

Practical example

A products API responds in JSON with fields like id, name, price and images. The API client decodes the response and displays the products in the interface. The same structure can be sent both ways: client to server or server to client. Any common programming language can convert a list of products to JSON and then read it back without losing information. The same JSON file can be sent to the server via an HTTP request and, at the destination, converted back into a list of objects, keeping id and price intact.

What it's used for

JSON is the web and APIs data exchange standard. It is lightweight, does not require expensive libraries and is easy to debug. Both in the browser and on the server, JSON is accepted as one of the classic communication formats. Many modern APIs use JSON because the client and server understand the structure without needing complicated exchange schemas. JSON is also used in application configuration files, where readability and simplicity help teams that are not systems specialists.

Difference between X and Y

JSON and XML are both data exchange formats, but JSON is lighter and simpler. XML brings more schema and namespace tools, but is more verbose. JSON does not replace XML in all scenarios, but dominates in modern APIs.