Add to Favorites

web development terminology - JSON

JSON is an abbreviation, it stands for javascript object notation. Don't let the "javascript" part of the definition fool you, this data format is not limited only to javascript. JSON is simply a data interchange format, it's layout is pretty simple. It consists mostly of associative arrays and simple data structures.

It is used mainly with ajax and javascript ( as an alternative to xml ) but it can also be used by any application to transmit data to other applications ( such as API calls over the web ). JSON was built as a subset of the javascript language, so it can be evaluated as true javascript and does not need to be parsed before it's data can be accessed by a javascript making an ajax call. This simple fact makes it much quicker at getting data from an ajax call and making it usable, xml can take quite a bit longer to parse out into a structure that is useful for your application.

An example of JSON:

{
"name": "john doe",
"title": "manager"
}

JSON can also be used a simple envelope to tell javascript if an action has succeeded, and relay a message back from an API. For example, an api exposes functionality to add an item to a database. The ajax backend will run some validation on the script and will need to tell the user if something is incorrect with the item. The javascript needs to know wether or not the operation it requested was successful and if not why it wasn't successful. A simple JSON response envelope:

{
"success": false,
"message": "your item must have at least 5 characters"
}

Your javascript can parse this as JSON using eval ( or any other JSON parsing method ) and see that the operation was not successful, and that it should tell the user that their item should have at least 5 characters.

Comments

Be the first to leave a comment on this post.

Leave a comment

To leave a comment, please log in / sign up