The JSON Format Explained

The JSON format is a very popular format for exchanging data. It is very easy to use. Find out, how to use the JSON format.

What is JSON?

JSON stands for JavaScript Object Notation. The format is identical to the way, you would create objects in JavaScript. It is a great way to exchange data between different technologies.

A typical example would be the interchange between a website and a webserver. The website could request data via JavaScript/Ajax form a webserver and process this data client-side. The webserver could, for example convert an PHP array to JSON and hand it to the client, which converts this JSON string to an javascript object.

The JSON structure

The following data types are supported by JSON:

Null value Keyword: null
Boolean Value Keywords true und false
Number Numbers from 0 to 9.
Also valid are:

  • negative values
  • a decimal point
  • an exponent
String Strings are covered with  .
Array Are covered with [ and ].

Arrays contain a comma separated list of values.

Object Covered with { and }.

Objects contain a comma separated list of properties.

Properties are always key-value pairs in an object.
Key and values are separated with an :

The key is a string. The property can be one of the datatypes described above.

So here is an example of an JSON Object:

{
	"product": "MP3-Player",
	"articlenumber": "12345",
	"price": 9.90,
	"currency": "EURO",
	"customer": {
		"name": "Mustermann",
		"firstname": "Paula",
		"newcustomer": true,
		"newsletter": [ "General", "Tech-Stuff", "News" ]
	}
}

This object has the properties:
product“, which is a string,
articlenumber“, which is a number,
price“, which is a decimal number,
currency“, which is a string,
customer“, which is an object.

The object customer has the following properties:
name“, which is a string,
firstname“, which is a string,
newcustomer“, which is a boolean value,
newsletter“, which is an array (with three elements)

(Visited 289 times, 1 visits today)

Leave a Comment