http://json.org/json-es.html
http://www.etnassoft.com/2010/12/30/tutorial-json/
http://javascriptweblog.wordpress.com/2010/11/29/json-and-jsonp/
http://www.anieto2k.com/2007/08/03/toma-de-contacto-con-json/
{
"name": "Eric Clapton",
"occupation": "Guitar Hero",
"bands": ["Cream", "Blind Faith"]
}
-
JSON (Javascript Object Notation) is a format for data exchange based on the literal notation of Javascript for the representation of objects, arrays, strings, booleans and numbers
http://tools.ietf.org/html/rfc4627 -
Advantages of this format versus XML :
- It's Lighter (its structure needs less elements that XML), that's why is ideal for AJAX requests
- It's easier to transform to a Javascript object
http://ajaxian.com/archives/json-vs-xml-the-debate
Stop Comparing JSON and XML -
Particularities of JSON format vs literal notation of Javascript:
- Pairs key-value always go with double quotes
- JSON can represent 6 types of values: objects, arrays, numbers, strings, booleans and null
- Dates are not recognised as data types
- Numbers cannot be preceeded by 0 (but decimals)
-
JSON strings must be converted to Javascript objects so they can be used (and the opposite). To do this we can use:
eval()
: Is note recommended using it directlyJSON.parse
: Converts a JSON string in an Javascript objectJSON.stringify
: Converts a Javascript object into a JSON stringjQuery.parseJSON
: with jQuery we can also do the JSON parse
JSON object (and its methods
JSON.parse
andJSON.stringify
) are available natively in all browsers compatible with ECMAScript 5http://json.parser.online.fr/
https://developer.mozilla.org/En/Using_JSON_in_Firefox
>>> JSON.parse('{"bar":"new property","baz":3}')
Object { bar="new property", baz=3}
>>> JSON.stringify({ breed: 'Turtle', occupation: 'Ninja' });
"{"breed":"Turtle","occupation":"Ninja"}"