Working with JSON for Web Development

This chapter will help you to learn JSON fundamentals, example, syntax, array, object, encode, decode, file, date and date format. You will also be able to learn JSON examples with other technologies such as Java and PHP.

JSON Array


JSON array represents ordered list of values. JSON array can store multiple values. It can store string, number, boolean or object in JSON array.

In JSON array, values must be separated by comma.

The [ (square bracket) represents JSON array.

{
   "employee": {
   "name": "sonoo",
   "salary": 56000,
   "married": true
    }
}

JSON Array of Strings

Let's see an example of JSON arrays storing string values.

["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

JSON Array of Numbers

Let's see an example of JSON arrays storing number values.

[12, 34, 56, 43, 95]

JSON Array of Booleans

Let's see an example of JSON arrays storing boolean values.

[true, true, false, false, true]

JSON Array of Objects

A simple JSON array example having 4 objects.

{"employees":[
     {"name":"Ram", "email":"ram@gmail.com", "age":23},
     {"name":"Shyam", "email":"shyam23@gmail.com", "age":28},
     {"name":"John", "email":"john@gmail.com", "age":33},
     {"name":"Bob", "email":"bob32@gmail.com", "age":41}
]}

JSON Multidimensional Array

We can store array inside JSON array, it is known as array of arrays or multidimensional array.

[
     [ "a", "b", "c" ],
     [ "m", "n", "o" ],
     [ "x", "y", "z" ]
]