The JSON format is very simple by design. It is represented by the following two data structures:
- An unordered collection of the name-value pairs (representing an object):
- Attributes of an object and their values are represented in the name-value pair format; the name and the value in a pair are separated by a colon (:). Names in an object are strings, and values may be of any of the valid JSON data types such as number, string, Boolean, array, object, or null. Each name:value pair in a JSON object is separated by a comma (,). The entire object is enclosed in curly braces ({}).
- For instance, the JSON representation of a department object is as follows:
{"departmentId":10, "departmentName":"IT",
"manager":"John Chen"}
-
- This example shows how you can represent the various attributes of a department, such as departmentId, departmentName, and manager in the JSON format.
- An ordered collection of values (representing an array):
- Arrays are enclosed in square brackets ([]), and their values are separated by a comma (,). Each value in an array may be of a different type, including another array or an object.
- The following example illustrates the use of array notation to represent the employees working in a department. You can also see an array of locations in this example:
{"departmentName":"IT",
"employees":[
{"firstName":"John", "lastName":"Chen"},
{"firstName":"Ameya", "lastName":"Job"},
{"firstName":"Pat", "lastName":"Fay"}
],
"location":["New York", "New Delhi"]
}