Way 2 Web

Web development tips


 
JSON

JSON - Javascript Object Notation, is a data format used to describe Javascript data types.

You'll see it used to describe Javascript objects.

It is a very useful way of building Javascript data objects and, since in theory it is language-independent, it may be used for data interchange as well.

The basics

{}
Curly brackets enclose an object
[]
Square brackets enclose an array
:
Colon delimits an element's name and value
,
Comma delimits elements

Examples

1. An array of objects

[{name:"elem1", value:21},
 {name:"elem2", value:"testing 1 2 3"},
 {name:"elem3", value:null}]

2. An object, one of the elements being an array

{name:"testObject", 
 id:10021,},
 colors: ["blue", "green", "red"]
}

3. Javascript, data object

A data object is defined and then used programmatically.

<script language="javascript">
    var data = {name:"testObject", id:10021, 
                colors:["blue", "green", "red"]};
    alert('This ID is:' + data.id);
    alert('Number of colors:' + data.colors.length);
</script>

JSON data objects are used to demonstrate the Linked Selection Javascript widget in a later section.

References