AllExperts > Encyclopedia 
Search      
Find out about volunteering to AllExperts

JSON: Encyclopedia BETA


Free Encyclopedia
 Home · Index · Browse A-Z  · Questions and Answers ·
Encyclopedia

Browse A-Z
ABCDEFGHIJKLMNOPQRSTUVWXYZNum


License
Disclaimer

 
 
 
 
Free Online Courses
12 Weeks to Weight Loss
Take Charge of Stress
Learn How to Bake
Budgeting 101
Deeper Faith
DIY Fashion Makeover

       MORE E-COURSES
 
   

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  Misc

JSON

JSON (pronounced as IPA , or like the English given name "Jason"), which stands for "JavaScript Object Notation", is a lightweight computer data interchange format. JSON is a subset of the object literal notation of JavaScript but its use does not require JavaScript.

The official MIME Media Type for JSON is application/json.

JSON's simplicity has resulted in its widespread use, especially as an alternative to XML in Ajax. One of the advantages of JSON over XML as a data interchange format in this context is that it is much easier to write a JSON parser. In JavaScript, JSON can be parsed trivially using the eval() procedure. This was important for the acceptance of JSON within the Ajax programming community because of JavaScript's ubiquity among web browsers.

In practice, arguments regarding ease of parser development or parser performance are rarely relevant due to security concerns regarding the use of eval() and the rise of built-in XML processing features in modern web browsers. For that reason JSON is typically used in environments where the size of the data stream between client and server is of paramount importance (hence its use by Google, Yahoo!, etc. which serve millions of users), where the source of the data can explicitly be trusted, and where the loss of fast access to client-side XSLT processing for data manipulation or UI generation is not a consideration.

While JSON is often positioned "against" XML, it's not uncommon to see both JSON and XML used in the same application. For example, a client-side application which integrates Google Maps data with SOAP weather data requires support for both data formats.

There is growing support for JSON through the use of lightweight third-party packages. The list of supported languages includes ActionScript, C, C#, ColdFusion, Common Lisp, E, Java, JavaScript, Lua, ML, Objective CAML, Perl, PHP, Python, Rebol, and Ruby.

In December 2005, Yahoo! began supporting JSON as an option for some of its Web services.

Using JSON

It is trivial to parse JSON in JavaScript using JavaScript's built in eval() function. For example:

http_request.open("GET", url, true);
 http_request.onreadystatechange = handle_json;
http_request.send(null);

 function handle_json()
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
var json_data = http_request.responseText;
var the_object = eval("(" + json_data + ")");
}
else
{
alert("There was a problem with the URL.");
}
http_request = null;
}
}

Note that the use of XMLHttpRequest in this example is not cross-browser although syntactic variations are available on Internet Explorer, Opera, Safari, and Mozilla-based browsers.

Browsers can also use (hidden)