JavaScript Object Notation (JSON) Compiled by  Adnan Sohail Software Engineer  i2c inc.
JSON <ul><li>JSON  (JavaScript Object Notation) is a lightweight data-interchange format.  </li></ul><ul><li>It is easy fo...
Why JSON? <ul><li>Because JSON is lightweight, easy to understand, manipulate and generate, it has almost replaced XML whi...
JSON Structures <ul><li>JSON is built on two structures: </li></ul><ul><ul><li>A collection of name/value pairs.  </li></u...
Syntax of JSON <ul><li>Object </li></ul><ul><ul><li>An  object  is an unordered set of name/value pairs.  </li></ul></ul><...
Syntax of JSON <ul><li>Array </li></ul><ul><ul><li>An  array  is an ordered collection of values.  </li></ul></ul><ul><ul>...
Syntax of JSON <ul><li>A  value  can be a  string  in double quotes, or a  number , or true or false or null, or an  objec...
JSON Example <ul><li>{ “students” :  </li></ul><ul><li>[ </li></ul><ul><li>{“id&quot;:1, &quot;name&quot;:&quot;Adnan Soha...
XML Example <ul><li><?xml version=&quot;1.0&quot; ?> </li></ul><ul><li><root> </li></ul><ul><li><student> </li></ul><ul><l...
Validating JSON & JSON Security <ul><li>JavaScript’s built-in method eval() is used to validate a JSON string. </li></ul><...
Using JSON APIs <ul><li>JSON strings can be easily generated using JSON APIs available at  http://json.org </li></ul><ul><...
Benefits of JSON over XML <ul><li>JSON supports data types like string, integer, boolean etc.  </li></ul><ul><li>JSON is n...
JSON References <ul><li>http://www.xul.fr/en-xml-ajax.html </li></ul><ul><li>http://www.xul.fr/ajax-javascript-json.html <...
Upcoming SlideShare
Loading in...5
×

Java Script Object Notation (JSON)

6,134

Published on

Java Script Object Notation (JSON)

Published in: Technology
2 Comments
7 Likes
Statistics
Notes
No Downloads
Views
Total Views
6,134
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
398
Comments
2
Likes
7
Embeds 0
No embeds

No notes for slide

Java Script Object Notation (JSON)

  1. 1. JavaScript Object Notation (JSON) Compiled by Adnan Sohail Software Engineer i2c inc.
  2. 2. JSON <ul><li>JSON (JavaScript Object Notation) is a lightweight data-interchange format. </li></ul><ul><li>It is easy for humans to read and write. </li></ul><ul><li>It is easy for machines to parse and generate. </li></ul><ul><li>It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. </li></ul><ul><li>JSON is a text format that is completely language independent. </li></ul><ul><li>These properties make JSON an ideal data-interchange language. </li></ul>
  3. 3. Why JSON? <ul><li>Because JSON is lightweight, easy to understand, manipulate and generate, it has almost replaced XML which was used previously as the only data-interchange format. </li></ul><ul><li>JSON is preferable because of the following reasons: </li></ul><ul><ul><li>XML is heavier than JSON </li></ul></ul><ul><ul><li>to parse XML, we have to use xPath which is an overhead removed in JSON because JSON is native to JavaScript </li></ul></ul><ul><ul><li>XML uses tags to describe user data and tags increase the size of data </li></ul></ul>
  4. 4. JSON Structures <ul><li>JSON is built on two structures: </li></ul><ul><ul><li>A collection of name/value pairs. </li></ul></ul><ul><ul><ul><li>In various languages, this is realized as an object , record, dictionary, hash table, keyed list, or associative array. </li></ul></ul></ul><ul><ul><li>An ordered list of values. </li></ul></ul><ul><ul><ul><li>In most languages, this is realized as an array , vector, list, or sequence. </li></ul></ul></ul>
  5. 5. Syntax of JSON <ul><li>Object </li></ul><ul><ul><li>An object is an unordered set of name/value pairs. </li></ul></ul><ul><ul><li>An object begins with {  (left brace) and ends with }  (right brace) . </li></ul></ul><ul><ul><li>Each name is followed by :  (colon) and the name/value pairs are separated by ,  (comma) . </li></ul></ul>
  6. 6. Syntax of JSON <ul><li>Array </li></ul><ul><ul><li>An array is an ordered collection of values. </li></ul></ul><ul><ul><li>An array begins with [  (left bracket) and ends with ]  (right bracket) . Values are separated by ,  (comma) . </li></ul></ul>
  7. 7. Syntax of JSON <ul><li>A value can be a string in double quotes, or a number , or true or false or null, or an object or an array . These structures can be nested. </li></ul><ul><li>A string is a collection of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string. </li></ul>
  8. 8. JSON Example <ul><li>{ “students” : </li></ul><ul><li>[ </li></ul><ul><li>{“id&quot;:1, &quot;name&quot;:&quot;Adnan Sohail&quot;}, </li></ul><ul><li>{“id&quot;:2, &quot;name&quot;:&quot;Irfan Razzaq&quot;} </li></ul><ul><li>] </li></ul><ul><li>} </li></ul>
  9. 9. XML Example <ul><li><?xml version=&quot;1.0&quot; ?> </li></ul><ul><li><root> </li></ul><ul><li><student> </li></ul><ul><li><id>1</id> </li></ul><ul><li><name>Adnan Sohail</name> </li></ul><ul><li></student> </li></ul><ul><li><student> </li></ul><ul><li><id>2</id> </li></ul><ul><li><name>Irfan Razzaq</name> </li></ul><ul><li></student> </li></ul><ul><li></root> </li></ul>
  10. 10. Validating JSON & JSON Security <ul><li>JavaScript’s built-in method eval() is used to validate a JSON string. </li></ul><ul><li>Note: </li></ul><ul><ul><li>Use eval() only when the source is authentic and trusted which means use it only if you are sure that the string passed to it is a valid JSON string </li></ul></ul><ul><li>When you’ve security risks use </li></ul><ul><li>var myObject = myJSONtext.parseJSON(); </li></ul><ul><li>Which is available in http://www.json.org/json.js </li></ul><ul><ul><li>but eval() is faster than parseJSON() </li></ul></ul>
  11. 11. Using JSON APIs <ul><li>JSON strings can be easily generated using JSON APIs available at http://json.org </li></ul><ul><li>There are two main classes available in org.json.* package </li></ul><ul><ul><li>org.json.JSONObject </li></ul></ul><ul><ul><li>org.json.JSONArray </li></ul></ul><ul><li>Strings can be generating from objects of JSONObject or JSONArray using their toString() methods </li></ul>
  12. 12. Benefits of JSON over XML <ul><li>JSON supports data types like string, integer, boolean etc. </li></ul><ul><li>JSON is native data format for JavaScript and therefore it faster for the browser to read and understand. </li></ul><ul><li>As JSON contains no tags but data and therefore less data to be transferred between client and the server. So, it’s lighter than XML. </li></ul><ul><li>Easy for humans to read and write. </li></ul>
  13. 13. JSON References <ul><li>http://www.xul.fr/en-xml-ajax.html </li></ul><ul><li>http://www.xul.fr/ajax-javascript-json.html </li></ul><ul><li>http://json.org/ </li></ul><ul><li>http://www.json.org/java/ </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×