SlideShare a Scribd company logo
JSON – Java Script Object
Notation
Written By:-Pankaj Srivastava
pankajshrivastav6@gmail.com
What is JSON
 JSON is a data interchange format
 Interactive Web 2.0 applications, no more use page
replacement. Data transfer without refreshing a page.
 The most important aspects of data transfer are
simplicity, extensibility, interoperability, openness and
human readability
 Key idea in AJAX – Asynchronous Java Script and XML.
Topics to cover
 Overview of the working of JSON
 Properties of JSON as a data format
 JSON with AJAX
 Advantages of using JSON with AJAX
 Security Concerns in using JSON
 Where does it fit the best
How does it work?
 JSON is a subset of Java Script. JSON can be parsed by
a Java Script parser.
 It can represent either complex or simple data as it has
data types
 They are Strings, Number, Boolean, Objects and Arrays
 E.g. of Object:
 { "name": "Jack ("Bee") Nimble", "format": { "type":
"rect", "width": 120, "interlace": false}}
 An array can be shown as
 ["Sunday", "Monday", "Tuesday", "Wednesday“]
 All data types are intuitive and similar to other programming
languages
 Also compatible with other languages like C, C++, C#,
ColdFusion, Python and many more.
Properties of JSON
 It's simultaneously human- and machine-
readable format.
 It has support for Unicode, allowing almost
any information in any human language to be
communicated;
 The self-documenting format that describes
structure and field names as well as specific
values.
 The strict syntax and parsing requirements
that allow the necessary parsing algorithms to
remain simple, efficient, and consistent;
 The ability to represent the most general
computer science data structures: records,
lists and trees.
JSON in AJAX
 JSON can be used in AJAX as follows:
 Include it in HTML directly
 <html>... <script> var data = JSONdata; </script>...
</html>
 JSON is used with XMLHttpRequest and can be
converted into a JavaScript structure
 responseData = eval('(' + responseText + ')');
 Another approach is to use an invisible <iframe> for data
communication. The server sends JSON text embedded in a script
in a document.
 <html><head><script> document.domain = ‘something.com’;
parent.deliver(JSONtext); </script></head></html>
 deliver is passed the incoming data structure.
Why is JSON better suited for
AJAX?
 JSON is widely used in AJAX. The X in AJAX stands for
XML.
 E.g.
 {
 "name": “Pankaj Kumar",
 "org": “India",
 }
 <?xml version='1.0‘ encoding='UTF-8'?>
 <element>
 <name>Pankaj Kumatr</name>
 <org>India</org>
 </element>
 JSON response at client side is:
 var name = eval('(' + req.responseText + ')').fullname.value;
 To access a composite element
 eval('(' + req.responseText + ')').xyz.abc.value;
 Thus, any level deep elements can be easily accessed.
 XML response at client side is:
 var root = req.responseXML;
 var name = root.getElementsByTagName(‘fullname’);
 To access a composite element
 root.getElementsByTagName(‘xyz’)[0].firstChild
 To access deeper levels we need more overhead.
 Reduced extensibility in XML
Security Concerns
 Same Origin Policy - JavaScript to access the contents of
a Webpage, both the JavaScript and the Web page must
originate from the same domain.
 Malicious website could serve up JavaScript that loads
sensitive information from other websites using a client's
credentials and communicates it back to the attacker.
 Although the malicious JavaScript can’t directly manipulate the
contents, it can view the execution of the JavaScript and store the
results it returns.
 This problem gets aggravated with JSON as the JSON arrays are
themselves JavaScript objects and any malicious user can view
them directly.
Where can JSON be used?
 JSON is a light weight data format that can be used for
transferring medium amounts of data.
 It can be used in Java Script and then rendered on HTML
pages
 AJAX has many applications for JSON
 Thus, use JSON for applications that are browser based.
References:
 www.json.org
 RFC 4627, Network Working Group D. Crockford
 Thank you

More Related Content

What's hot

JSON - (English)
JSON - (English)JSON - (English)
JSON - (English)
Senior Dev
 
07 objective-c session 7
07  objective-c session 707  objective-c session 7
07 objective-c session 7
Amr Elghadban (AmrAngry)
 
Json
JsonJson
Json processing
Json processingJson processing
Json processing
Ahmed Gamil
 
An Introduction to JSON JavaScript Object Notation
An Introduction to JSON JavaScript Object NotationAn Introduction to JSON JavaScript Object Notation
An Introduction to JSON JavaScript Object Notation
Ahmed Muzammil
 
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
George McKinney
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)Raghu nath
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo db
Eman Mohamed
 
Ajax
AjaxAjax
NoSQL - "simple" web monitoring
NoSQL - "simple" web monitoringNoSQL - "simple" web monitoring
NoSQL - "simple" web monitoring
Samir Siqueira
 
Json
JsonJson
DOM-XML
DOM-XMLDOM-XML
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
Knoldus Inc.
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
S.Shayan Daneshvar
 
Overview on NoSQL and MongoDB
Overview on NoSQL and MongoDBOverview on NoSQL and MongoDB
Overview on NoSQL and MongoDB
harithakannan
 

What's hot (20)

JSON - (English)
JSON - (English)JSON - (English)
JSON - (English)
 
07 objective-c session 7
07  objective-c session 707  objective-c session 7
07 objective-c session 7
 
Json
JsonJson
Json
 
Json processing
Json processingJson processing
Json processing
 
Json
JsonJson
Json
 
An Introduction to JSON JavaScript Object Notation
An Introduction to JSON JavaScript Object NotationAn Introduction to JSON JavaScript Object Notation
An Introduction to JSON JavaScript Object Notation
 
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
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Quick overview on mongo db
Quick overview on mongo dbQuick overview on mongo db
Quick overview on mongo db
 
Ajax
AjaxAjax
Ajax
 
NoSQL - "simple" web monitoring
NoSQL - "simple" web monitoringNoSQL - "simple" web monitoring
NoSQL - "simple" web monitoring
 
Json
JsonJson
Json
 
DOM-XML
DOM-XMLDOM-XML
DOM-XML
 
Unit 2.3
Unit 2.3Unit 2.3
Unit 2.3
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
Xml processors
Xml processorsXml processors
Xml processors
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Overview on NoSQL and MongoDB
Overview on NoSQL and MongoDBOverview on NoSQL and MongoDB
Overview on NoSQL and MongoDB
 
Unit 2.3
Unit 2.3Unit 2.3
Unit 2.3
 

Similar to Json – java script object notation

Json
Json Json
JSON Injection
JSON InjectionJSON Injection
Web Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONSWeb Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONS
RSolutions
 
Json
JsonJson
Json
Uma mohan
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
Raveendra R
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
Julie Iskander
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializing
ssusere19c741
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2kriszyp
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
Santhiya Grace
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problemstitanlambda
 
JSON & AJAX.pptx
JSON & AJAX.pptxJSON & AJAX.pptx
JSON & AJAX.pptx
dyumna2
 
Software development - the java perspective
Software development - the java perspectiveSoftware development - the java perspective
Software development - the java perspective
Alin Pandichi
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
guestfd7d7c
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
Collaboration Technologies
 
Import web resources using R Studio
Import web resources using R StudioImport web resources using R Studio
Import web resources using R Studio
Rupak Roy
 

Similar to Json – java script object notation (20)

Json
Json Json
Json
 
JSON Injection
JSON InjectionJSON Injection
JSON Injection
 
Web Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONSWeb Development Course - AJAX & JSON by RSOLUTIONS
Web Development Course - AJAX & JSON by RSOLUTIONS
 
Json
JsonJson
Json
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
 
Copy of ajax tutorial
Copy of ajax tutorialCopy of ajax tutorial
Copy of ajax tutorial
 
Json
JsonJson
Json
 
Working with XML and JSON Serializing
Working with XML and JSON SerializingWorking with XML and JSON Serializing
Working with XML and JSON Serializing
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
 
Json
JsonJson
Json
 
JSON & AJAX.pptx
JSON & AJAX.pptxJSON & AJAX.pptx
JSON & AJAX.pptx
 
Software development - the java perspective
Software development - the java perspectiveSoftware development - the java perspective
Software development - the java perspective
 
Ajax
AjaxAjax
Ajax
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
Import web resources using R Studio
Import web resources using R StudioImport web resources using R Studio
Import web resources using R Studio
 
Ajax
Ajax Ajax
Ajax
 

Recently uploaded

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 

Recently uploaded (20)

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 

Json – java script object notation

  • 1. JSON – Java Script Object Notation Written By:-Pankaj Srivastava pankajshrivastav6@gmail.com
  • 2. What is JSON  JSON is a data interchange format  Interactive Web 2.0 applications, no more use page replacement. Data transfer without refreshing a page.  The most important aspects of data transfer are simplicity, extensibility, interoperability, openness and human readability  Key idea in AJAX – Asynchronous Java Script and XML.
  • 3. Topics to cover  Overview of the working of JSON  Properties of JSON as a data format  JSON with AJAX  Advantages of using JSON with AJAX  Security Concerns in using JSON  Where does it fit the best
  • 4. How does it work?  JSON is a subset of Java Script. JSON can be parsed by a Java Script parser.  It can represent either complex or simple data as it has data types  They are Strings, Number, Boolean, Objects and Arrays  E.g. of Object:  { "name": "Jack ("Bee") Nimble", "format": { "type": "rect", "width": 120, "interlace": false}}
  • 5.  An array can be shown as  ["Sunday", "Monday", "Tuesday", "Wednesday“]  All data types are intuitive and similar to other programming languages  Also compatible with other languages like C, C++, C#, ColdFusion, Python and many more.
  • 6. Properties of JSON  It's simultaneously human- and machine- readable format.  It has support for Unicode, allowing almost any information in any human language to be communicated;  The self-documenting format that describes structure and field names as well as specific values.  The strict syntax and parsing requirements that allow the necessary parsing algorithms to remain simple, efficient, and consistent;  The ability to represent the most general computer science data structures: records, lists and trees.
  • 7. JSON in AJAX  JSON can be used in AJAX as follows:  Include it in HTML directly  <html>... <script> var data = JSONdata; </script>... </html>  JSON is used with XMLHttpRequest and can be converted into a JavaScript structure  responseData = eval('(' + responseText + ')');
  • 8.  Another approach is to use an invisible <iframe> for data communication. The server sends JSON text embedded in a script in a document.  <html><head><script> document.domain = ‘something.com’; parent.deliver(JSONtext); </script></head></html>  deliver is passed the incoming data structure.
  • 9. Why is JSON better suited for AJAX?  JSON is widely used in AJAX. The X in AJAX stands for XML.  E.g.  {  "name": “Pankaj Kumar",  "org": “India",  }  <?xml version='1.0‘ encoding='UTF-8'?>  <element>  <name>Pankaj Kumatr</name>  <org>India</org>  </element>
  • 10.  JSON response at client side is:  var name = eval('(' + req.responseText + ')').fullname.value;  To access a composite element  eval('(' + req.responseText + ')').xyz.abc.value;  Thus, any level deep elements can be easily accessed.
  • 11.  XML response at client side is:  var root = req.responseXML;  var name = root.getElementsByTagName(‘fullname’);  To access a composite element  root.getElementsByTagName(‘xyz’)[0].firstChild  To access deeper levels we need more overhead.  Reduced extensibility in XML
  • 12. Security Concerns  Same Origin Policy - JavaScript to access the contents of a Webpage, both the JavaScript and the Web page must originate from the same domain.  Malicious website could serve up JavaScript that loads sensitive information from other websites using a client's credentials and communicates it back to the attacker.
  • 13.  Although the malicious JavaScript can’t directly manipulate the contents, it can view the execution of the JavaScript and store the results it returns.  This problem gets aggravated with JSON as the JSON arrays are themselves JavaScript objects and any malicious user can view them directly.
  • 14. Where can JSON be used?  JSON is a light weight data format that can be used for transferring medium amounts of data.  It can be used in Java Script and then rendered on HTML pages  AJAX has many applications for JSON  Thus, use JSON for applications that are browser based.
  • 15. References:  www.json.org  RFC 4627, Network Working Group D. Crockford  Thank you