Professional Documents
Culture Documents
transport JavaScript objects between a browser and web server. However, today the
name is a bit of a misnomer since JSON can be used as a data transportation format
with virtually any popular programming language.
JSON has become the default choice for formatting data for use in interactive web
applications. It has a very lightweight syntax and is very easy to learn, read, and
write.
History of JSON
JSON wasn�t invented, it was �discovered.� While he wasn�t the first to use JSON,
Douglas Crockford is typically credited with discovering the format because he was
the first to popularize and specify its use around the year 2001. However, in a
presentation to Yahoo! Developers, Crockford reveals that he discovered that JSON
was in use at Netscape as early as 1996.
Originally, Crockford thought of JSON as part of the JavaScript language and named
it accordingly. However, since JSON consists of nothing more than commas, curly
braces, square brackets, and data, it can be easily parsed into an array or object
by any programming language. Because of it�s language independence, JSON was
established as a standalone ECMA standard in 2013 (ECMA-404) and then extended and
referenced by Internet Engineering Task Force (IETF) Request For Comment (RFC) 7159
one year later.
Web service APIs use JSON format to make data available to third-party
applications.
AJAX interactions often use JSON to shuttle data between a server and a visitor�s
browser.
In both cases, client-side manipulation of JSON with JavaScript will be necessary
to render the data. In addition, if the data is going to be used to perform any
action on a web server, then a server-side programming language and language-
specific JSON library will do the work on the server.
{
"event": "breakfast",
"location": "Tiffany's",
"remember": true,
"format": "film",
"bothKindaLikedIt": true,
"thingsInCommon": 1
}
Ok, now things are getting a little more interesting. In this object, we have six
name-value pairs. Each name is a string and the values consist of three strings,
two boolean values, and one number.
We have time for one more example. In this case, a more complex object with nested
arrays and objects.
{
"contentManagementSystems" : [
{
"name": "WordPress",
"percentMarketShare": 58.9
},
{
"name": "Joomla",
"percentMarketShare": 6.1
},
{
"name": "Drupal",
"percentMarketShare": 4.9
}
]
}
We started things out with a single name-value pair using the name
"contentManagementSystems". The value is a somewhat complex array (we know that
because of the square brackets) that contains the rest of the data in the object.
However, rather than holding simple values, each value in the array is a nested
name-value pair (also known as an object and identified as such by the curly
braces).
In other words, this is a JSON object that contains an array of objects. Got it?
Good.
Resources
So now you know what JSON is, but maybe you want to learn how to actually use JSON.
If so, you�re in luck. Here are some of the finest JSON resources the web has to
offer:
Learn to use JSON with Java by reading Java API for JSON Processing: An
Introduction to JSON from the Oracle Technology Network.
The Java JSON Tutorial from Jenkov.com covers three popular Java JSON parsers and
links to another tutorial by the same author that will teach you how to build your
own JSON parser.
Use JSON with PHP by referring to the JSON section of the PHP Manual. As of PHP
5.2, JSON has been bundled in the PHP core. As a result, using JSON with a PHP
application is as simple as familiarizing yourself with the various JSON functions
built into the language.
If you want to master the use of JSON in PHP take a look at Handling JSON Like a
Boss in PHP: an in-depth tutorial that tackles advanced techniques.
Apply JSON to the .NET framework by referring to An Introduction to JavaScript
Object Notation (JSON) in JavaScript and .NET from the Microsoft Developer Network.
Books
If you prefer your education to printed and bound form, here are three of the best
JSON texts money can buy: