Some gathered notes on Javascript Object Notation
JSON, simply put, is a way of declaring an object in javascript.
JSON includes a way to describe arrays.
JSON is a subset of the Object literal.
The squiggly brackets surround the entire object.
Whereas an array holds a list in a certain order, an object is an unordered collection.
Objects hold attributes that point to values.
A value could be one number or a single line of text. Or, a value can be an array
Attributes are in quotes, because they are a string that holds the name of the attribute.
After the quotes comes a colon, which separates the attribute from the value.
JSON uses object literal notation. The form:
var person = {
“name”: “Douglas Adams”
“age”: 42
};
Is exactly the same (for all intents and purposes) as:
var person = new Object();
person.name = “Douglas Adams”;
person.age = 42;
You can also use
person[“age”]
this is the same as
person.age
The following example shows the JSON representation of an object that describes a person. The object has string fields for first name and last name, a number field for age, contains an object representing the person’s address, and contains a list (an array) of phone number objects.
{
“firstName”: “John”,
“lastName”: “Smith”,
“age”: 25,
“address”:
{
“streetAddress”: “21 2nd Street”,
“city”: “New York”,
“state”: “NY”,
“postalCode”: “10021”
},
“phoneNumber”:
[
{
“type”: “home”,
“number”: “212 555-1234”
},
{
“type”: “fax”,
“number”: “646 555-4567”
}
]
}
Valid example
{ “movies” : [
{ “title” : “1408”, “link” : “tt0450385”, “cover” : “MV5BMTk1MDg0NTU0OV5BMl5BanBnXkFtZTcwMTM1NDk0MQ”, “category” : “Horror”, “year” : “2007”, “description” : “” },
{ “title” : “2001: A Space Odyssey”, “link” : “tt0062622”, “cover” : “MV5BMjExMjgwNDk0NV5BMl5BanBnXkFtZTYwNzM4NDc4”, “category” : “Cult”, “year” : “1968”, “description” : “” },
{ “title” : “28 Days Later…”, “link” : “tt0289043”, “cover” : “MV5BNzM2NDYwNjM3OF5BMl5BanBnXkFtZTYwNDYxNzk5”, “category” : “Horror”, “year” : “2002”, “description” : “” },
{ “title” : “28 Weeks Later”, “link” : “tt0463854”, “cover” : “MV5BMTUxMjc2MTcxNV5BMl5BanBnXkFtZTcwMzgzOTY0MQ”, “category” : “Disturbing”, “year” : “2007”, “description” : “Robert Carlyle makes a lasting impression in the movie with his role of a man trying to survive in a land plagued by a rage-virus which acts as sort of like aggressive rabies. What makes 28 Weeks Later stand out from other zombie survival horrors is the setting which is more believable because the infected are not actually dead nor comical in any way but just really terrifying.” },
{ “title” : “? l’int?rieur”, “link” : “tt0856288”, “cover” : “MV5BMjA2NDk4NTYwOV5BMl5BanBnXkFtZTcwNTQ3NjQ2MQ”, “category” : “Disturbing”, “year” : “2007”, “description” : “Bloody and cruel, Inside is another French quality horror that manages to leave an impression for a long time after watching. The story and the setting might be somewhat simplistic for the film focuses almost solely on one emotion. Agony. Agony of the characters in the film and agony of the viewer watching their peril.” }]}
Valid eval example
“{\”movielist\”: [\”Friday the 13th\”, \”Friday the 13th Part 2\”, \”Friday the 13th Part III\”, \”Friday the 13th: The Final Chapter\”, \”Friday the 13th: A New Beginning\”]}”
JSON (pronounced like “Jason”): short for JavaScript Object Notation, is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays. The official Internet media type for JSON is “application/json”. The JSON file extension is .json.
The JSON format is often used for serialization, transmitting structured data over a network connection. Its main application is in Ajax web application programming, where it serves as an alternative to the use of the XML format. JSON is supported by MSIE 5.5+, Mozilla/4.0 and most of other browsers.