JSON (JavaScript Object Notation) is an easy-to-work-with format for describing structured data. Before you start working with JSON, familiarize yourself with basic programming jargon. It is also recommended to have a text editor with JSON support (you can also use an online editor).
To describe structured data, JSON uses objects and arrays.
Objects consist of properties and their values. Because the values in an object are identified by names (property names), they are not kept in a particular order.
The following object describes John Doe using two properties : firstName
and lastName
.
Notice that the object is enclosed in {}
. The properties and values are both in double quotes and are separated
by a colon. The individual properties are separated from each other using commas.
As objects collect named values, arrays are ordered lists of values that do not have a property name but are identified by their numeric position.
Let’s go on to describing John Doe’s family using an array (marked by []
) of three objects:
Objects are also separated from each other by commas. Notice that the last item (property or object) is not followed by a comma.
The terminology varies a lot and other expressions are also commonly used:
Each property value always has one of the following data types:
true
or false
The types string
, number
, integer
and boolean
represent scalar values (simple). The types array
and
object
represent structured values (they are composed of other values). For example:
Notice that only strings and property names are enclosed in double quotes. The boolean value is false
without
double quotes because false
, true
and null
(no or an unknown value) are keywords, not strings.
There are multiple ways to refer to particular properties in a JSON document (for instance, JSONPath. For the purpose of this documentation, we will use simple dot notation. Let’s consider this JSON describing the Doe’s family:
To refer to John’s city, we would write address.city
. To refer to little Jimmy’s shoe size, we
would write members[2].shoeSize
. Array items indexes are zero-based, so the third item has
index 2
.
The order of items in an object is not important. It is also worth noting that []
represents an empty array and
{}
represents an empty object.
This page contains a little introduction to JSON documents. We intentionally avoided many details, but you should now understand what JSON is, and how to write some stuff in it.