JavaScript EditorFreeware JavaScript Editor     Ajax Tutorials 

Main Page

Previous Page
Next Page

What Is JSON?

JSON is a very lightweight data format based on a subset of the JavaScript syntax, namely array and object literals. Because it uses JavaScript syntax, JSON definitions can be included within JavaScript files and accessed without the extra parsing that comes along with XML-based languages. But before you can use JSON, it's important to understand the specific JavaScript syntax for array and object literals.

Array Literals

For those unfamiliar with JavaScript literal notation, array literals are specified by using square brackets ([ and ]) to enclose a comma-delimited list of JavaScript values (meaning a string, number, Boolean, or null value), such as:

var aNames = ["Benjamin", "Michael", "Scott"];

You can then access the values in the array by using the array name and bracket notation:

alert(aNames[0]);   //outputs "Benjamin"
alert(aNames[1]);   //outputs "Michael"
alert(aNames[2]);   //outputs "Scott"

Note that the first position in the array is 0, and the value in that position is "Benjamin".

Because arrays in JavaScript are not typed, they can be used to store any number of different data types:

var aValues = ["string", 24, true, null];

This array contains a string, followed by a number, followed by a Boolean, followed by a null value. This is completely legal and perfectly fine JavaScript.

If you were to define an array without using literal notation, you would have to use the Array constructor, such as:

var aValues = new Array("string", 24, true, null);

Previous Page
Next Page

Туры в Черногорию на сайте - лучшие цены!

JavaScript EditorAjax Editor     Ajax Validator