SlideShare a Scribd company logo
JSON
BITM 3730
Developing Web Applications
Previous Work Review
• http://pirate.shu.edu/~marinom6/work.html
• Please Note only previously due HW assignments are posted on my
pirate.shu.edu web space
• Begin organizing your creating files for this course into an easy to find folder
on your desktop for easy FTP later on
JSON Basics
• JSON stands for JavaScript Object Notation
• JSON is easier to parse than XML
• Properties make up a JSON object
• JSON.parse() parses retrieved data
• JSON.stringify() converts a JavaScript object into a string
JSON vs. XML
• Syntax for storing and exchanging
data
• Similar to XML:
• Hierarchical – values embedded
within values
• Human readable
• Both can use XMLHttpRequest
• Different from XML:
• No tags
• Shorter
• Quicker to read and write
• JSON uses arrays
• Easier to parse JSON
JSON Object Example
• A car is an object which has three properties describing it
• Make – String value representing the make of the car
• Model – String value representing the model of the car
• Price – Numeric value representing the price of the car
How That Looks in XML
<car>
<make>Chevrolet</make>
<model>Suburban</model>
<price>60000</price>
</car>
How It Looks in JSON
{
"make": "Chevrolet",
"model": "Suburban",
"price": 60000
}
JSON Data Types
• String – {“name”:”Mark”}
• Number – {“age”: 41}
• Objects –
• {
“address”: {“name”:”Matt Marnio”, “email”:”matt.marino@shu.edu”}
}
• Arrays –
• {
“students”:[“Manny”, “Moe”, “Jack”]
}
• Booleans - {“Full-time”: true}
• Null – {“Job Description”: null}
Accessing Values in Objects
• In order to access the values of an object, you can
use the dot (.) notation
myObj =
{“firstName”:”Matt”,”lastName”:”Marino”,”
age”:34};
firstName = myObj.firstName;
lastName = myObj.lastName;
age = myObj.age;
• You can also access the values using a bracket
notation
firstName = myObj[“firstName”];
lastName = myObj[“lastName”];
age = myObj[“age”];
• You can also access all of the values using a for
loop:
for (x in myObj)
{
}
Parsing
• When data is received from a web server, it can be parsed with JSON.parse() and it
becomes a JavaScript object.
var text = '{ "name":"John", "birth":"1986-12-14", "city":"New York"}';
var obj = JSON.parse(text);
obj.birth = new Date(obj.birth);
document.getElementById("demo").innerHTML = obj.name + ", " + obj.birth;
Stringify
• Convert a JavaScript object into a string
var obj = { "name":"John", "age":30, "city":"New York"};
var myJSON = JSON.stringify(obj);
document.getElementById("demo").innerHTML = myJSON
Building Assignment 8
<html>
<head>
<script>
</script>
</head>
<body>
</body>
</html>
Building Assignment 8
<script>
var obj = { "name":"John", "age":30, "city":"New York"};
var myJSON = JSON.stringify(obj);
document.getElementById("demo").innerHTML = myJSON
</script>
Building Project 3 – Reminder of XML Code
<xml>
<instructors>
<name>Professors</name>
<contact>
<name>Matt Marino</name>
<email>matt.marino@shu.edu</email>
</contact>
</instructors>
</xml>
Building Project 3 – JSON Code
{
“name": “Matt Marino",
“email": “matt.marino@shu.edu",
}
• Create additional ones for each professor you have this semester
JSON Example
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="js/scripts.js"></script>
</head>
<body onload="show()">
<div id="carJSON"></div>
<div id="carXML"></div>
</body>
</html>
JSON Example Visual
JSON XML
function showJSON()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
document.getElementById("carJSON").innerHTML = myObj.make;
}
};
xmlhttp.open("GET", "cars.json", true);
xmlhttp.send();
}
function showXML()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xmldoc = xmlhttp.responseXML;
var myObj = xmldoc.getElementsByTagName("make");
alert(myObj[0].childNodes[0].nodeValue);
document.getElementById("carXML").innerHTML =
myObj[0].childNodes[0].nodeValue;
}
};
xmlhttp.open("GET", "cars.xml", true);
xmlhttp.send();
}
function show()
{
showJSON();
showXML();
}
JSON Table
<!DOCTYPE html>
<html>
<body>
<h2>Make a table based on JSON data.</h2>
<p id="demo"></p>
<script>
var obj, dbParam, xmlhttp, myObj, x, txt = "";
obj = { table: "customers", limit: 14 };
dbParam = JSON.stringify(obj);
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
txt += "<table border='1'>"
for (x in myObj) {
txt += "<tr><td>" + myObj[x].name + "</td></tr>";
}
txt += "</table>"
document.getElementById("demo").innerHTML = txt;
}
};
xmlhttp.open("POST", "json_demo_html_table.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("x=" + dbParam);
</script>
</body>
</html>
JSON Table Visual
JSON Community
• https://www.json.org/json-en.html
• Goes in depth on all JSON topics
• Including using JSON with various programming languages

More Related Content

PDF
Introduction to JSON
PDF
CS8651 IP Unit 2 pdf regulation -2017 anna university
PDF
Intro to JSON
PPTX
Unit-2.pptx
PDF
JSON Learning
PPTX
PPTX
JSON
Introduction to JSON
CS8651 IP Unit 2 pdf regulation -2017 anna university
Intro to JSON
Unit-2.pptx
JSON Learning
JSON

Similar to BITM3730Week8.pptx (20)

PPTX
JSON & AJAX.pptx
PPTX
JSON - (English)
PDF
JSON in JavaScript
PPT
java script json
PPT
Java Script Object Notation (JSON)
PPTX
JSON.pptx
PPT
json.ppt download for free for college project
PDF
Basics of JSON (JavaScript Object Notation) with examples
PDF
Json tutorial, a beguiner guide
PDF
Json
PPTX
Introduction to JSON & AJAX
PPTX
module 2.pptx for full stack mobile development application on backend applic...
PDF
JavaScript Lessons 2023 V2
PPTX
JSON: The Basics
PDF
Unit-2 JSON.pdf
JSON & AJAX.pptx
JSON - (English)
JSON in JavaScript
java script json
Java Script Object Notation (JSON)
JSON.pptx
json.ppt download for free for college project
Basics of JSON (JavaScript Object Notation) with examples
Json tutorial, a beguiner guide
Json
Introduction to JSON & AJAX
module 2.pptx for full stack mobile development application on backend applic...
JavaScript Lessons 2023 V2
JSON: The Basics
Unit-2 JSON.pdf

More from MattMarino13 (20)

PPTX
INFO 2106 2-17-25.pptx Course Slide Deck
PPTX
INFO 2105 PPTs Fall 2024 ---------------
PPTX
1-22-24 INFO 2106.pptx
PPTX
1-24-24 INFO 3205.pptx
PPTX
BITM3730 11-14.pptx
PPTX
01_Felke-Morris_Lecture_ppt_ch01.pptx
PPTX
02slide_accessible.pptx
PPTX
Hoisington_Android_4e_PPT_CH01.pptx
PPTX
AndroidHTP3_AppA.pptx
PPTX
9780357132302_Langley11e_ch1_LEAP.pptx
PPTX
krajewski_om12 _01.pptx
PPTX
CapsimOpsIntroPPT.Marino.pptx
PPTX
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
PPTX
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
PPTX
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
PPTX
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
PPTX
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
PPTX
1-23-19 Agenda.pptx
PPTX
EDF 8289 Marino PPT.pptx
PPTX
Agenda January 20th 2016.pptx
INFO 2106 2-17-25.pptx Course Slide Deck
INFO 2105 PPTs Fall 2024 ---------------
1-22-24 INFO 2106.pptx
1-24-24 INFO 3205.pptx
BITM3730 11-14.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptx
02slide_accessible.pptx
Hoisington_Android_4e_PPT_CH01.pptx
AndroidHTP3_AppA.pptx
9780357132302_Langley11e_ch1_LEAP.pptx
krajewski_om12 _01.pptx
CapsimOpsIntroPPT.Marino.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
1-23-19 Agenda.pptx
EDF 8289 Marino PPT.pptx
Agenda January 20th 2016.pptx

Recently uploaded (20)

PDF
Types of Literary Text: Poetry and Prose
PPTX
Strengthening open access through collaboration: building connections with OP...
PPTX
Introduction and Scope of Bichemistry.pptx
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PDF
High Ground Student Revision Booklet Preview
PPTX
How to Manage Global Discount in Odoo 18 POS
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
UTS Health Student Promotional Representative_Position Description.pdf
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PDF
5.Universal-Franchise-and-Indias-Electoral-System.pdfppt/pdf/8th class social...
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Sunset Boulevard Student Revision Booklet
PPTX
Presentation on Janskhiya sthirata kosh.
PDF
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...
Types of Literary Text: Poetry and Prose
Strengthening open access through collaboration: building connections with OP...
Introduction and Scope of Bichemistry.pptx
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
UPPER GASTRO INTESTINAL DISORDER.docx
High Ground Student Revision Booklet Preview
How to Manage Global Discount in Odoo 18 POS
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
102 student loan defaulters named and shamed – Is someone you know on the list?
Week 4 Term 3 Study Techniques revisited.pptx
UTS Health Student Promotional Representative_Position Description.pdf
How to Manage Starshipit in Odoo 18 - Odoo Slides
5.Universal-Franchise-and-Indias-Electoral-System.pdfppt/pdf/8th class social...
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Module 3: Health Systems Tutorial Slides S2 2025
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Sunset Boulevard Student Revision Booklet
Presentation on Janskhiya sthirata kosh.
Cell Biology Basics: Cell Theory, Structure, Types, and Organelles | BS Level...

BITM3730Week8.pptx

  • 2. Previous Work Review • http://pirate.shu.edu/~marinom6/work.html • Please Note only previously due HW assignments are posted on my pirate.shu.edu web space • Begin organizing your creating files for this course into an easy to find folder on your desktop for easy FTP later on
  • 3. JSON Basics • JSON stands for JavaScript Object Notation • JSON is easier to parse than XML • Properties make up a JSON object • JSON.parse() parses retrieved data • JSON.stringify() converts a JavaScript object into a string
  • 4. JSON vs. XML • Syntax for storing and exchanging data • Similar to XML: • Hierarchical – values embedded within values • Human readable • Both can use XMLHttpRequest • Different from XML: • No tags • Shorter • Quicker to read and write • JSON uses arrays • Easier to parse JSON
  • 5. JSON Object Example • A car is an object which has three properties describing it • Make – String value representing the make of the car • Model – String value representing the model of the car • Price – Numeric value representing the price of the car
  • 6. How That Looks in XML <car> <make>Chevrolet</make> <model>Suburban</model> <price>60000</price> </car>
  • 7. How It Looks in JSON { "make": "Chevrolet", "model": "Suburban", "price": 60000 }
  • 8. JSON Data Types • String – {“name”:”Mark”} • Number – {“age”: 41} • Objects – • { “address”: {“name”:”Matt Marnio”, “email”:”[email protected]”} } • Arrays – • { “students”:[“Manny”, “Moe”, “Jack”] } • Booleans - {“Full-time”: true} • Null – {“Job Description”: null}
  • 9. Accessing Values in Objects • In order to access the values of an object, you can use the dot (.) notation myObj = {“firstName”:”Matt”,”lastName”:”Marino”,” age”:34}; firstName = myObj.firstName; lastName = myObj.lastName; age = myObj.age; • You can also access the values using a bracket notation firstName = myObj[“firstName”]; lastName = myObj[“lastName”]; age = myObj[“age”]; • You can also access all of the values using a for loop: for (x in myObj) { }
  • 10. Parsing • When data is received from a web server, it can be parsed with JSON.parse() and it becomes a JavaScript object. var text = '{ "name":"John", "birth":"1986-12-14", "city":"New York"}'; var obj = JSON.parse(text); obj.birth = new Date(obj.birth); document.getElementById("demo").innerHTML = obj.name + ", " + obj.birth;
  • 11. Stringify • Convert a JavaScript object into a string var obj = { "name":"John", "age":30, "city":"New York"}; var myJSON = JSON.stringify(obj); document.getElementById("demo").innerHTML = myJSON
  • 13. Building Assignment 8 <script> var obj = { "name":"John", "age":30, "city":"New York"}; var myJSON = JSON.stringify(obj); document.getElementById("demo").innerHTML = myJSON </script>
  • 14. Building Project 3 – Reminder of XML Code <xml> <instructors> <name>Professors</name> <contact> <name>Matt Marino</name> <email>[email protected]</email> </contact> </instructors> </xml>
  • 15. Building Project 3 – JSON Code { “name": “Matt Marino", “email": “[email protected]", } • Create additional ones for each professor you have this semester
  • 16. JSON Example <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="js/scripts.js"></script> </head> <body onload="show()"> <div id="carJSON"></div> <div id="carXML"></div> </body> </html>
  • 17. JSON Example Visual JSON XML function showJSON() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var myObj = JSON.parse(this.responseText); document.getElementById("carJSON").innerHTML = myObj.make; } }; xmlhttp.open("GET", "cars.json", true); xmlhttp.send(); } function showXML() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var xmldoc = xmlhttp.responseXML; var myObj = xmldoc.getElementsByTagName("make"); alert(myObj[0].childNodes[0].nodeValue); document.getElementById("carXML").innerHTML = myObj[0].childNodes[0].nodeValue; } }; xmlhttp.open("GET", "cars.xml", true); xmlhttp.send(); } function show() { showJSON(); showXML(); }
  • 18. JSON Table <!DOCTYPE html> <html> <body> <h2>Make a table based on JSON data.</h2> <p id="demo"></p> <script> var obj, dbParam, xmlhttp, myObj, x, txt = ""; obj = { table: "customers", limit: 14 }; dbParam = JSON.stringify(obj); xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myObj = JSON.parse(this.responseText); txt += "<table border='1'>" for (x in myObj) { txt += "<tr><td>" + myObj[x].name + "</td></tr>"; } txt += "</table>" document.getElementById("demo").innerHTML = txt; } }; xmlhttp.open("POST", "json_demo_html_table.php", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send("x=" + dbParam); </script> </body> </html>
  • 20. JSON Community • https://www.json.org/json-en.html • Goes in depth on all JSON topics • Including using JSON with various programming languages