| Introduction to JSON |
|
|
| Written by Administrator | |
| Saturday, 28 April 2007 | |
|
Web services are practically synonymous with XML, the payload format used for communicating between client and server. However, the application architecture imposed by the appearance of Ajax and REST techniques has forced many to contemplate alternatives like JavaScript Object Notation (JSON). According to JSON JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. The JavaScript Object Notation, or JSON, is a lightweight syntax for representing data. JSON's elegance comes from the fact that it's a subset of the JavaScript language itself. 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, contains an object representing the person's address, and contains a list of phone numbers (an array). {The first thing you should realize about JSON is that it remains a simple text format—just like XML—which is relatively easy to read and inspect with the naked eye. At a syntax level, what starts to set JSON apart from other formats is the characters used to separate data, which are mainly constrained to apostrophes ', brackets ( ), [ ], { }, colons :, and commas ,. This listing illustrates what a JSON payload looks like: { To place this last JSON example in context, this listing shows the equivalent payload written in XML: <addressbook> As you can see, JSON has structure with nesting of data elements, just as XML does. JSON too is text-based, as XML is. Both use Unicode. JSON is just as readable by humans as XML is. Subjectively, JSON is clearer and has less redundancy. The JSON Web site describes the syntax of JSON rigorously, and yet does so briefly. It really is a simple little language! XML is certainly appropriate for marking up documents, but JSON is ideal for data interchange. Each instance of a JSON document describes one object with nested objects, arrays, strings, numbers, boolean values, or null values. In these address card examples, the JSON version is lighter weight, taking 682 bytes of space, whereas the XML version requires 744. That's not a spectacular savings, of course. The real benefits come in the parsing.
Trackback(0)
Comments (1)
![]() Write comment
Copyright 2007. All Rights Reserved. |
|
| Last Updated ( Saturday, 28 April 2007 ) |
| < Prev | Next > |
|---|









