SlideShare a Scribd company logo
1 of 44
Unit-2
JSAON
JSON Introduction
• JSON: JavaScript Object Notation.
• JSON is a syntax for storing and exchanging
data.
• JSON is text, written with JavaScript object
notation.
Exchanging Data
• When exchanging data between a browser and a
server, the data can only be text.
• JSON is text, and we can convert any JavaScript
object into JSON, and send JSON to the server.
• We can also convert any JSON received from the
server into JavaScript objects.
• This way we can work with the data as JavaScript
objects, with no complicated parsing and
translations.
Sending Data
Receiving Data
JSON Syntax
• The JSON syntax is a subset of the JavaScript
syntax.
JSON Syntax Rules
JSON syntax is derived from JavaScript object
notation syntax:
• Data is in name/value pairs
• Data is separated by commas
• Curly braces hold objects
• Square brackets hold arrays
JSON Data - A Name and a Value
JSON - Evaluates to JavaScript Objects
JSON Values
• In JSON, values must be one of the following data types:
• a string
• a number
• an object (JSON object)
• an array
• a boolean
• null
• In JavaScript values can be all of the above, plus any other valid
JavaScript expression, including:
• a function
• a date
• undefined
• In JSON, string values must be written with double quotes:
Example of JSON values
JSON Uses JavaScript Syntax
JSON vs XML
• Both JSON and XML can be used to receive
data from a web server
• XML is used for data storage
• XML is used for data transmission.
• XML and JSON are used extensive in
WebServices.
The following JSON and XML examples both define an
employees object, with an array of 3 employees:
JSON VS XML
JSON is Like XML Because
• Both JSON and XML are "self describing"
(human readable)
• Both JSON and XML are hierarchical (values
within values)
• Both JSON and XML can be parsed and used
by lots of programming languages
• Both JSON and XML can be fetched with an
XMLHttpRequest
JSON VS XML
JSON is Unlike XML Because
• JSON doesn't use end tag
• JSON is shorter
• JSON is quicker to read and write
• JSON can use arrays
JSON VS XML
The biggest difference is:
• XML has to be parsed with an XML parser.
JSON can be parsed by a standard JavaScript
function.
Why JSON is Better Than XML?
• XML is much more difficult to parse than
JSON.
• JSON is parsed into a ready-to-use JavaScript
object
JSON VS XML
For AJAX applications, JSON is faster and easier than
XML:
Using XML
• Fetch an XML document
• Use the XML DOM to loop through the document
• Extract values and store in variables
Using JSON
• Fetch a JSON string
• JSON.Parse the JSON string
JSON Data Types
Valid Data Types
In JSON, values must be one of the following data
types:
a string
a number
an object (JSON object)
an array
a boolean
null
JSON Data Types
JSON Data Types
JSON.parse()
• A common use of JSON is to exchange data
to/from a web server.
• When receiving data from a web server, the
data is always a string.
• Parse the data with JSON.parse(), and the data
becomes a JavaScript object.
Parsing Functions
Functions are not allowed in JSON.
If you need to include a function, write it as a string.
You can convert it back into a function later:
Output
JSON.stringify()
• A common use of JSON is to exchange data
to/from a web server.
• When sending data to a web server, the data
has to be a string.
• Convert a JavaScript object into a string
with JSON.stringify().
JSON Object
JSON Arrays
• Arrays in JSON are almost the same as arrays
in JavaScript.
• In JSON, array values must be of type string,
number, object, array, boolean or null.
• In JavaScript, array values can be all of the
above, plus any other valid JavaScript
expression, including functions, dates,
and undefined.
Arrays in JSON Objects
• Arrays can be values of an object property:
JSON Arrays
• Accessing Array Values
• You access the array values by using the index
number:
Output
JSON.parse()
• common use of JSON is to exchange data
to/from a web server.
• When receiving data from a web server, the
data is always a string.
• Parse the data with JSON.parse(), and the data
becomes a JavaScript object.
JSON From the Server
• You can request JSON from the server by using
an AJAX request
• As long as the response from the server is
written in JSON format, you can parse the
string into a JavaScript object.
JSON From the Server
The onreadystatechange Property
• The readyState property holds the status of
the XMLHttpRequest.
• The onreadystatechange property defines a
function to be executed when the readyState
changes.
• The status property and
the statusText property holds the status of the
XMLHttpRequest object.
Parsing Dates
• Date objects are not allowed in JSON.
• If you need to include a date, write it as a
string.
• You can convert it back into a date object
later:
output
JSON Arrays

More Related Content

Similar to Unit-2.pptx

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
 
Devoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and JacksonDevoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and Jackson
srondal
 
module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...
HemaSenthil5
 

Similar to Unit-2.pptx (20)

JSON Processing and mule
JSON Processing and muleJSON Processing and mule
JSON Processing and mule
 
JSON.pptx
JSON.pptxJSON.pptx
JSON.pptx
 
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
 
Devoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and JacksonDevoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and Jackson
 
Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
java script json
java script jsonjava script json
java script json
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
JSON_FIles-Py (2).pptx
JSON_FIles-Py (2).pptxJSON_FIles-Py (2).pptx
JSON_FIles-Py (2).pptx
 
Hackolade Tutorial - part 2 - Overview of JSON and JSON schema
Hackolade Tutorial - part 2 - Overview of JSON and JSON schemaHackolade Tutorial - part 2 - Overview of JSON and JSON schema
Hackolade Tutorial - part 2 - Overview of JSON and JSON schema
 
Unit-2 JSON.pdf
Unit-2 JSON.pdfUnit-2 JSON.pdf
Unit-2 JSON.pdf
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Json
JsonJson
Json
 
module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
Json
JsonJson
Json
 
Introduction to JSON
Introduction to JSONIntroduction to JSON
Introduction to JSON
 
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
 
Speed Up Your APEX Apps with JSON and Handlebars
Speed Up Your APEX Apps with JSON and HandlebarsSpeed Up Your APEX Apps with JSON and Handlebars
Speed Up Your APEX Apps with JSON and Handlebars
 
An introduction to json
An introduction to jsonAn introduction to json
An introduction to json
 

Recently uploaded

Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
MarinCaroMartnezBerg
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
shivangimorya083
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
shambhavirathore45
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
shivangimorya083
 

Recently uploaded (20)

Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 

Unit-2.pptx

  • 2. JSON Introduction • JSON: JavaScript Object Notation. • JSON is a syntax for storing and exchanging data. • JSON is text, written with JavaScript object notation.
  • 3. Exchanging Data • When exchanging data between a browser and a server, the data can only be text. • JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server. • We can also convert any JSON received from the server into JavaScript objects. • This way we can work with the data as JavaScript objects, with no complicated parsing and translations.
  • 6. JSON Syntax • The JSON syntax is a subset of the JavaScript syntax. JSON Syntax Rules JSON syntax is derived from JavaScript object notation syntax: • Data is in name/value pairs • Data is separated by commas • Curly braces hold objects • Square brackets hold arrays
  • 7. JSON Data - A Name and a Value
  • 8. JSON - Evaluates to JavaScript Objects
  • 9. JSON Values • In JSON, values must be one of the following data types: • a string • a number • an object (JSON object) • an array • a boolean • null • In JavaScript values can be all of the above, plus any other valid JavaScript expression, including: • a function • a date • undefined • In JSON, string values must be written with double quotes:
  • 10. Example of JSON values
  • 12.
  • 13. JSON vs XML • Both JSON and XML can be used to receive data from a web server • XML is used for data storage • XML is used for data transmission. • XML and JSON are used extensive in WebServices.
  • 14. The following JSON and XML examples both define an employees object, with an array of 3 employees:
  • 15. JSON VS XML JSON is Like XML Because • Both JSON and XML are "self describing" (human readable) • Both JSON and XML are hierarchical (values within values) • Both JSON and XML can be parsed and used by lots of programming languages • Both JSON and XML can be fetched with an XMLHttpRequest
  • 16. JSON VS XML JSON is Unlike XML Because • JSON doesn't use end tag • JSON is shorter • JSON is quicker to read and write • JSON can use arrays
  • 17. JSON VS XML The biggest difference is: • XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function.
  • 18. Why JSON is Better Than XML? • XML is much more difficult to parse than JSON. • JSON is parsed into a ready-to-use JavaScript object
  • 19. JSON VS XML For AJAX applications, JSON is faster and easier than XML: Using XML • Fetch an XML document • Use the XML DOM to loop through the document • Extract values and store in variables Using JSON • Fetch a JSON string • JSON.Parse the JSON string
  • 20. JSON Data Types Valid Data Types In JSON, values must be one of the following data types: a string a number an object (JSON object) an array a boolean null
  • 23. JSON.parse() • A common use of JSON is to exchange data to/from a web server. • When receiving data from a web server, the data is always a string. • Parse the data with JSON.parse(), and the data becomes a JavaScript object.
  • 24.
  • 25. Parsing Functions Functions are not allowed in JSON. If you need to include a function, write it as a string. You can convert it back into a function later: Output
  • 26. JSON.stringify() • A common use of JSON is to exchange data to/from a web server. • When sending data to a web server, the data has to be a string. • Convert a JavaScript object into a string with JSON.stringify().
  • 27.
  • 28.
  • 29.
  • 31. JSON Arrays • Arrays in JSON are almost the same as arrays in JavaScript. • In JSON, array values must be of type string, number, object, array, boolean or null. • In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined.
  • 32. Arrays in JSON Objects • Arrays can be values of an object property:
  • 33. JSON Arrays • Accessing Array Values • You access the array values by using the index number:
  • 35.
  • 36. JSON.parse() • common use of JSON is to exchange data to/from a web server. • When receiving data from a web server, the data is always a string. • Parse the data with JSON.parse(), and the data becomes a JavaScript object.
  • 37.
  • 38. JSON From the Server • You can request JSON from the server by using an AJAX request • As long as the response from the server is written in JSON format, you can parse the string into a JavaScript object.
  • 39. JSON From the Server
  • 40. The onreadystatechange Property • The readyState property holds the status of the XMLHttpRequest. • The onreadystatechange property defines a function to be executed when the readyState changes. • The status property and the statusText property holds the status of the XMLHttpRequest object.
  • 41.
  • 42. Parsing Dates • Date objects are not allowed in JSON. • If you need to include a date, write it as a string. • You can convert it back into a date object later: