Category Archives: JSON



  • JavaScript Object Notation
  • JSON is a text format that is programming-language independent and is a native data form of JavaScript. It is lighter and faster than XML because it needs less markup compared to XML.
  • JSON is not a JavaScript; it is basically a specification or a subset derived from JavaScript.
  • JSON expects the data to be UTF-8 whereas PHP adheres to ISO-8859-1 encoding by default.

According to the JSON specification, the following types are allowed in JSON:

Object: An object is a collection of key-value pairs enclosed between { and } and separated by a comma. The key and the value themselves are separated using a colon (:). Think of objects as associative arrays or hash tables. Keys are simple strings and values can be an array, string, number, boolean, or null.

Array: Like other languages, an array is an ordered pair of data. For representing an array, values are comma separated and enclosed between [ and ].

String: A string must be enclosed in double quotes. Note that single quotes are not allowed.

An example:

			"name": "Rafiqul Islam",
			"age": 28,
			"isAdult": true
			"name": "Adrita Islam",
			"age": 3,
			"isAdult": false

(click here for another example)

Following is a valid JavaScript object but not a valid JSON.

	'name': 'Superman', 
	'address': 'anywhere'

JSON requires that the name and value must be enclosed in double quotes; single quotes are not allowed.

Reff: PHP JQuery Cookbook by Vijay Joshi