JSON Syntax

A syntax of JSON is similar to JavaScript objects, but still, JSON has some differences.

Rules for writing JSON syntax

Following are the rules for writing JSON syntax-

  • JSON data starts with the opening braces({) and ends with the closing braces(}).
  • JSON is the collection of key and value pair separated by the comma.
  • Key and value are separated by the colon (:). Key is placed on the left side of a colon and value is put on the right side of a colon.
  • Square brackets are used to store JSON array.
  • Curly brackets are used to hold JSON objects.
  • JSON key must be a string and must be enclosed in double quotes. If you try to enclose it in single quotes, you will get an error.
  • If the data type of value is a string, then you must enclose it in double quotes.

{
	"key_1":value_1,
	"key_2":value_2,
	"key_3":value_3,
	.....
	.....
	"key_n":value_n
}

JSON Exmaple

{
	"name":"Samsung Galaxy J7",
	"price":15500,
	"color":["black", "white", "grey"],
	"inStock":true,
	"features":{
		"screen size":5.5,
		"operating system":"android 6.0",
		"wireless charging":false,
		"connectivity":["wi-fi", "4G LTE", "bluetooth"]
	}
}