SlideShare a Scribd company logo
JavaScript Object Notation (JSON) Compiled by  Adnan Sohail Software Engineer  i2c inc.
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. These properties make JSON an ideal data-interchange language.
Why JSON? 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.  JSON is preferable because of the following reasons: XML is heavier than JSON  to parse XML, we have to use xPath which is an overhead removed in JSON because JSON is native to JavaScript  XML uses tags to describe user data and tags increase the size of data
JSON Structures JSON is built on two structures: A collection of name/value pairs.  In various languages, this is realized as an  object , record, dictionary, hash table, keyed list, or associative array. An ordered list of values.  In most languages, this is realized as an  array , vector, list, or sequence.
Syntax of JSON Object An  object  is an unordered set of name/value pairs.  An object begins with  {  (left brace)  and ends with  }  (right brace) .  Each name is followed by  :  (colon)   and the name/value pairs are separated by  ,  (comma) .
Syntax of JSON Array An  array  is an ordered collection of values.  An array begins with  [  (left bracket)   and ends with  ]  (right bracket) . Values are separated by  ,  (comma) .
Syntax of JSON 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. 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.
JSON Example { “students” :  [ {“id":1, "name":"Adnan Sohail"}, {“id":2, "name":"Irfan Razzaq"} ] }
XML Example <?xml version=&quot;1.0&quot; ?> <root> <student> <id>1</id> <name>Adnan Sohail</name> </student> <student> <id>2</id> <name>Irfan Razzaq</name> </student> </root>
Validating JSON & JSON Security JavaScript’s built-in method eval() is used to validate a JSON string. Note: 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 When you’ve security risks use var myObject = myJSONtext.parseJSON(); Which is available in  http://www.json.org/json.js   but eval() is faster than parseJSON()
Using JSON APIs JSON strings can be easily generated using JSON APIs available at  http://json.org There are two main classes available in  org.json.*  package org.json.JSONObject org.json.JSONArray Strings can be generating from objects of  JSONObject  or  JSONArray  using their  toString()  methods
Benefits of JSON over XML JSON supports data types like string, integer, boolean etc.  JSON is native data format for JavaScript and therefore it faster for the browser to read and understand.  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.  Easy for humans to read and write.
JSON References http://www.xul.fr/en-xml-ajax.html http://www.xul.fr/ajax-javascript-json.html http://json.org/ http://www.json.org/java/

More Related Content

What's hot (20)

Json
JsonJson
Json
Sabarinath Gnanasekar
 
XSLT
XSLTXSLT
XSLT
Kamal Acharya
 
Css box-sizing
Css box-sizingCss box-sizing
Css box-sizing
Webtech Learning
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
Reem Alattas
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testers
tlvd
 
Json
JsonJson
Json
krishnapriya Tadepalli
 
JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)
BOSS Webtech
 
Triggers and Stored Procedures
Triggers and Stored ProceduresTriggers and Stored Procedures
Triggers and Stored Procedures
Tharindu Weerasinghe
 
An introduction to bootstrap
An introduction to bootstrapAn introduction to bootstrap
An introduction to bootstrap
Mind IT Systems
 
Xpath
XpathXpath
Xpath
Manav Prasad
 
Sql select
Sql select Sql select
Sql select
Mudasir Syed
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Bootstrap
BootstrapBootstrap
Bootstrap
AvinashChunduri2
 
Css Display Property
Css Display PropertyCss Display Property
Css Display Property
Webtech Learning
 
HTML
HTMLHTML
HTML
Doeun KOCH
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
Compare Infobase Limited
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
Edureka!
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Edureka!
 
데이터베이스 프로젝트 최종보고서
데이터베이스 프로젝트 최종보고서데이터베이스 프로젝트 최종보고서
데이터베이스 프로젝트 최종보고서
Young-jun Park
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
Reem Alattas
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testers
tlvd
 
JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)
BOSS Webtech
 
An introduction to bootstrap
An introduction to bootstrapAn introduction to bootstrap
An introduction to bootstrap
Mind IT Systems
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
Edureka!
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Edureka!
 
데이터베이스 프로젝트 최종보고서
데이터베이스 프로젝트 최종보고서데이터베이스 프로젝트 최종보고서
데이터베이스 프로젝트 최종보고서
Young-jun Park
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 

Viewers also liked (20)

Json tutorial
Json tutorialJson tutorial
Json tutorial
Mohammed Bilal
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
Robert MacLean
 
JSON - Quick Overview
JSON - Quick OverviewJSON - Quick Overview
JSON - Quick Overview
Signure Technologies
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
Halil Burak Cetinkaya
 
Intoduction to php restful web service
Intoduction to php  restful web serviceIntoduction to php  restful web service
Intoduction to php restful web service
baabtra.com - No. 1 supplier of quality freshers
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
Hoan Vu Tran
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
Nitin Pande
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
Stormpath
 
RESTful web
RESTful webRESTful web
RESTful web
Alvin Qi
 
Introduction to RESTful Webservice
Introduction to RESTful WebserviceIntroduction to RESTful Webservice
Introduction to RESTful Webservice
Eftakhairul Islam
 
C++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+OperatorsC++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+Operators
Mohammad Shaker
 
Java script
Java scriptJava script
Java script
Abhishek Kesharwani
 
Inside jQuery (2011)
Inside jQuery (2011)Inside jQuery (2011)
Inside jQuery (2011)
Kenneth Auchenberg
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
Napendra Singh
 
Android json parser tutorial – example
Android json parser tutorial – exampleAndroid json parser tutorial – example
Android json parser tutorial – example
Rajat Ghai
 
Fundamental JQuery
Fundamental JQueryFundamental JQuery
Fundamental JQuery
Achmad Solichin
 
When Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentalsWhen Ajax Attacks! Web application security fundamentals
When Ajax Attacks! Web application security fundamentals
Simon Willison
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Siva Arunachalam
 
HTML/CSS/java Script/Jquery
HTML/CSS/java Script/JqueryHTML/CSS/java Script/Jquery
HTML/CSS/java Script/Jquery
FAKHRUN NISHA
 
Ad

Similar to Java Script Object Notation (JSON) (20)

JSON - (English)
JSON - (English)JSON - (English)
JSON - (English)
Senior Dev
 
Json training
Json trainingJson training
Json training
Elavarasi Dc
 
JSON
JSONJSON
JSON
Zara Tariq
 
All about XML, JSON and related topics..
All about XML, JSON and related topics..All about XML, JSON and related topics..
All about XML, JSON and related topics..
tinumanueltmt
 
json.pptx
json.pptxjson.pptx
json.pptx
Anum Zehra
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
George McKinney
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
AnujSood25
 
Json
JsonJson
Json
soumya
 
json.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college project
AmitSharma397241
 
Json
JsonJson
Json
Zainal Abdul Kahar
 
J s-o-n-120219575328402-3
J s-o-n-120219575328402-3J s-o-n-120219575328402-3
J s-o-n-120219575328402-3
Ramamohan Chokkam
 
1 Json Intro and datatype PRESENTATION.pptx
1 Json Intro and datatype PRESENTATION.pptx1 Json Intro and datatype PRESENTATION.pptx
1 Json Intro and datatype PRESENTATION.pptx
angelinjeba6
 
JSON.pptx
JSON.pptxJSON.pptx
JSON.pptx
TilakaRt
 
Json
JsonJson
Json
baabtra.com - No. 1 supplier of quality freshers
 
Json
JsonJson
Json
Anderson Oliveira
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
Sanjeev Kumar Jaiswal
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
Mark Daniel Dacer
 
Json
JsonJson
Json
Anand Kumar Rajana
 
Json – java script object notation
Json – java script object notationJson – java script object notation
Json – java script object notation
Dilip Kumar Gupta
 
Java script and json
Java script and jsonJava script and json
Java script and json
Islam Abdelzaher
 
Ad

Recently uploaded (20)

Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 

Java Script Object Notation (JSON)

  • 1. JavaScript Object Notation (JSON) Compiled by Adnan Sohail Software Engineer i2c inc.
  • 2. 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. These properties make JSON an ideal data-interchange language.
  • 3. Why JSON? 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. JSON is preferable because of the following reasons: XML is heavier than JSON to parse XML, we have to use xPath which is an overhead removed in JSON because JSON is native to JavaScript XML uses tags to describe user data and tags increase the size of data
  • 4. JSON Structures JSON is built on two structures: A collection of name/value pairs. In various languages, this is realized as an object , record, dictionary, hash table, keyed list, or associative array. An ordered list of values. In most languages, this is realized as an array , vector, list, or sequence.
  • 5. Syntax of JSON Object An object is an unordered set of name/value pairs. An object begins with {  (left brace) and ends with }  (right brace) . Each name is followed by :  (colon) and the name/value pairs are separated by ,  (comma) .
  • 6. Syntax of JSON Array An array is an ordered collection of values. An array begins with [  (left bracket) and ends with ]  (right bracket) . Values are separated by ,  (comma) .
  • 7. Syntax of JSON 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. 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.
  • 8. JSON Example { “students” : [ {“id&quot;:1, &quot;name&quot;:&quot;Adnan Sohail&quot;}, {“id&quot;:2, &quot;name&quot;:&quot;Irfan Razzaq&quot;} ] }
  • 9. XML Example <?xml version=&quot;1.0&quot; ?> <root> <student> <id>1</id> <name>Adnan Sohail</name> </student> <student> <id>2</id> <name>Irfan Razzaq</name> </student> </root>
  • 10. Validating JSON & JSON Security JavaScript’s built-in method eval() is used to validate a JSON string. Note: 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 When you’ve security risks use var myObject = myJSONtext.parseJSON(); Which is available in http://www.json.org/json.js but eval() is faster than parseJSON()
  • 11. Using JSON APIs JSON strings can be easily generated using JSON APIs available at http://json.org There are two main classes available in org.json.* package org.json.JSONObject org.json.JSONArray Strings can be generating from objects of JSONObject or JSONArray using their toString() methods
  • 12. Benefits of JSON over XML JSON supports data types like string, integer, boolean etc. JSON is native data format for JavaScript and therefore it faster for the browser to read and understand. 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. Easy for humans to read and write.
  • 13. JSON References http://www.xul.fr/en-xml-ajax.html http://www.xul.fr/ajax-javascript-json.html http://json.org/ http://www.json.org/java/