JavaScript Object Notation (JSON) is a lightweight data-interchange format. JSON is self-describing and easy for humans to read and write. It is the most commonly used data format on the web and for RESTful web services.
The following is a simple example of the JSON format describing customer group data containing two customer groups with customer group IDs of 10 and 20, with the additional Description and PaymentTermId fields:
{
"CustomerGroupId":"10",
"Description":"Wholesales customers",
"PaymentTermId":"Net30"
},
{
"CustomerGroupId":"20",
"Description":"Retail customers",
"PaymentTermId":"Receipt"
}
Another little complex example of the JSON data format describing personal details is shown here. The following example represents personal details, including address, phone number, and children and spouse details:
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
},
{
"type": "mobile",
"number": "123 456-7890"
}
],
"children": [],
"spouse": null
}
As we mentioned earlier, this is easily readable by humans, and at the same time, lighter and easy to parse by a computer program. These characteristics make JSON the preferred data type for web and cloud applications.