Tutorial Image

JSON Object | JSON Object Literal

JSON object literal has the following characteristics:

  • JSON object literal is written inside the curly braces {}.
  • It contains key/value pairs i.e {key1:value,key2:value2} that are separated by a colon : and key must be a string and always placed inside double quotes and value must be valid JSON data type such as string, number, object, array, boolean, null, etc.
  • The Key is always on the left side of the colon and it will be always string and must be placed inside the double quote.

Example


JSON String & JSON Object Literal

When JSON object literal is surrounded by a single quote then it will be formed JSON string. Whenever a single quote is removed from the JSON string then it can be formed JSON object literal.

Below is an example of a JSON string.


JSON object literal is exist inside JSON string:


Please keep in mind that JSON is a string, not an object.

Creating Javascript Object Using JSON Literal

Javascript object can be created by JSON object literal.

Source Code

Try it now

Creating Javascript Object From JSON String

Javascript object is created by parsing JSON string. Let us see it.

Source Code

Try it now

Accessing Object Values

Object value can be access though the (.) operator.

Source Code

Try it now

object values can also be access by using bracket ([]) notation.

Source Code

Try it now