What Is JSON?
JSON is a lightweight text-based format for representing structured data. It is widely used by websites, APIs, applications and programming languages to exchange information in a form that is relatively easy for both humans and computers to understand.
JSON means JavaScript Object Notation
JSON stands for JavaScript Object Notation.
It is a text-based format used to represent structured information using objects, arrays, names and values.
Although JSON originated from JavaScript syntax, it is now used independently by many programming languages and software systems.
What does JSON look like?
Suppose we want to store information about a customer.
This is a JSON object.
Each piece of information consists of a name and a value.
JSON uses name-value pairs
Consider this line:
The name of the property is:
and its value is:
A colon separates the property name from its value. Commas separate different properties.
JSON objects use curly braces
An object begins with { and ends with }.
Objects are useful when several named properties belong to the same thing.
JSON arrays use square brackets
An array represents an ordered collection of values.
Arrays begin with [ and end with ].
Arrays can contain objects
This is extremely common when working with APIs and databases.
Here, the array contains three separate customer objects.
JSON supports several kinds of values
| Type | Example |
|---|---|
| String | "Freelance Coder" |
| Number | 42 |
| Boolean | true |
| Null | null |
| Object | { "name": "Alice" } |
| Array | [1, 2, 3] |
JSON strings use double quotation marks
JSON requires strings and property names to use double quotation marks.
Important: JSON does not allow property names or strings to be written using single quotation marks in standard JSON syntax.
JSON can represent true and false
Boolean values are written without quotation marks.
JSON can represent no value
The value null represents the intentional absence of a value.
JSON can represent complex structures
Objects can contain other objects and arrays.
This creates a hierarchical structure in which related information can be grouped together.
JSON is widely used by APIs
One of JSON's most important uses is transferring data between software systems.
For example, an application might request information about a product from an API and receive:
The application can then read the JSON and use the values in its own interface or processing.
JSON helps systems communicate
JSON provides a common structure that both sides can understand.
JSON and CSV solve different problems
CSV works particularly well for simple tabular data.
JSON can represent more complex nested structures.
| CSV | JSON |
|---|---|
| Rows and columns | Objects and arrays |
| Excellent for tables | Excellent for structured data |
| Flat structure | Can be nested |
JSON and XML can represent similar data
This XML:
could be represented in JSON as:
JSON is often more compact for application data, while XML provides additional features that can be useful for document-oriented and specialised systems.
JSON is a text format
JSON may represent complex information, but the underlying document is still text.
This means JSON can be opened in a text editor, transmitted over a network and processed by many different programming languages.
JSON and UTF-8
JSON exchanged between systems is commonly encoded using UTF-8.
UTF-8 allows JSON to represent a very wide range of Unicode characters reliably.
JSON can be stored in .json files
JSON data saved as a standalone file normally uses the .json file extension.
JSON does not have to exist as a separate file, however. It can also be sent directly between applications and APIs.
Why is JSON so widely used?
Readable
Its structure is relatively easy for people to inspect and understand.
Lightweight
JSON can represent structured information without large amounts of additional markup.
Structured
Objects, arrays and nested values can represent sophisticated data structures.
Widely supported
Most modern programming languages and web technologies can read and generate JSON.
Where is JSON used?
JSON syntax is strict
Valid JSON must follow specific rules.
Property names use double quotes.
Strings use double quotes.
Properties are separated by commas.
Trailing commas are not permitted in standard JSON.
For example, this is valid:
But this is not valid standard JSON:
Simple text. Structured information.
JSON is a text-based format for representing structured data using objects, arrays and name-value pairs. Its simplicity, flexibility and widespread software support make it one of the most important formats for APIs, websites, applications, automation and modern data exchange.