SlideShare a Scribd company logo
1 of 17
JSON - Javascript
Object Notation
Prepared by: Ms Panda
Selling your idea
What is JSON?
- JSON is a Syntax for storing and exchanging data. It’s
a lightweight data-interchange format
- It means Javascript Object Notation.
- And it’s a text, written with Javascript Object
Notation.
- JSON is “self-describing” and easy to understand.
Also it’s language independent since text can be read
and used as a data format by any programming
language.
Selling your idea
Exchanging Data? How?
- When exchanging data between a browser and a
server, data can only be text.
- Since JSON is a text, so we can convert any
javascript Object into JSON and then send off to a
server.
Selling your idea
Exchanging Data? How?
- Not just converting Javascript Object into JSON, we
also can reverse the converting from JSON into
Javascript Object.
- By this way, we can work with Data as Javascript
Object, with no complicated Parsing and Translating.
Selling your idea
Sending data:
function login(username, pwd) {
var userObject = { "name" : username, "password" : pwd }
$.ajax({
url: "http://api-ams.me/v1/api/authentication",
type: "POST",
data: JSON.stringify(userObject),
success: function(response) {
console.log(“Successfully”);
},
error: function(error) {
console.log(“Error”);
}
})
}
Selling your idea
Receiving data:
function loadUser(id) {
$.ajax({
url: "http://api-ams.me/v1/api/users/"+id,
type: "GET",
success: function(response) {
console.log(response.data);
},
error: function(error) {
console.log(“Error”);
}
})
}
Selling your idea
Why use JSON?
- Since the JSON format is text only, it can easily be
sent to and from a server as seen in example above.
Besides, JSON is used as a data format by any
programming language.
- In Javascript, JSON.parse() is a built-in function to
convert a string - written in JSON format, into native
Javascript object.
Selling your idea
JSON Syntax:
- The JSON syntax is a subset of the Javascript syntax.
Rule:
➔ Data is in name/value pairs
➔ Data is separated by commas
➔ Curly braces hold objects
➔ Square brackets hold arrays
Selling your idea
JSON Data - A name and a value
- JSON data is written as name/value pairs. A
name/value pairs consists of a field name (in double
quotes), followed by a colon, followed by a value:
Example: "username" : "Jung"
Note: JSON names required double quotes. Javascript
names don’t.
Selling your idea
JSON - Evaluates to Javascript Objects
- The JSON format is almost identical to Javascript
objects.
JSON:
{ "username" : "Jung" }
JavaScript
{ username : "Jung" }
Selling your idea
JSON Value/Data Type
- In JSON, values must be one
of the following data types:
➔ String
➔ Number
➔ Object (JSON object)
➔ Array
➔ Boolean
- In JavaScript, values can also
be:
➔ Function
➔ Data
➔ Undefined
Selling your idea
JSON Data Types
JSON Strings: { "username":"Jung" }
JSON Numbers: { "age":28 }
JSON Objects: { "data":{
"username":"Jung",
"Age" : 28}
}
JSON Arrays: { "employees":[
"John", "Anna", "Peter" ] }
JSON Boolean: { "gender":true }
JSON Null: { "children":null }
Selling your idea
JSON Objects
Syntax: { "name" : "value" }
- JSON objects are surrounded by curly braces { }.
- JSON objects are written in key/value pairs.
- Keys must be strings, and values must be a valid
JSON data type (string, number, object, array,
boolean or null).
- Keys and values are separated by a colon.
- Each key/value pair is separated by a comma.
Selling your idea
JSON Objects - Accessing Object Values
- You can access the object values by using dot (.)
notation:
Example: var username = data.name
Selling your idea
JSON Objects - Looping an Object
- You can loop thru object properties by using for-in
loop:
Example:
user = { "name":"Jung", "age":28, "house":null };
for (x in user) {
document.getElementById("demo").innerHTML
+= x;
}
Selling your idea
JSON Files
➔ The file type for JSON files is “.json
➔ The MIME type of JSON text is “application/json”
➔ MIME - Multipurpose Internet Mail Extensions
➔ Link: https://en.wikipedia.org/wiki/MIME
Good luck!
Thank you!

More Related Content

What's hot

What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?codeandyou forums
 
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB
 
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 Jacksonsrondal
 
Writing Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON SchemaWriting Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON SchemaYos Riady
 
Schema Design
Schema DesignSchema Design
Schema DesignMongoDB
 
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
 
JSON and JSON Schema in Oxygen
JSON and JSON Schema in OxygenJSON and JSON Schema in Oxygen
JSON and JSON Schema in OxygenOctavian Nadolu
 
R-Users Group JSON and ReST Introduction using Twitter
R-Users Group JSON and ReST Introduction using TwitterR-Users Group JSON and ReST Introduction using Twitter
R-Users Group JSON and ReST Introduction using TwitterKevin Smith
 
What is JSON? | JSON vs XML | Edureka
What is JSON? | JSON vs XML | EdurekaWhat is JSON? | JSON vs XML | Edureka
What is JSON? | JSON vs XML | EdurekaEdureka!
 
Networkin II Estructuras con MongoDB y Javascript
Networkin II Estructuras con MongoDB y JavascriptNetworkin II Estructuras con MongoDB y Javascript
Networkin II Estructuras con MongoDB y JavascriptVíctor Mejía
 

What's hot (19)

Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
 
Json
JsonJson
Json
 
java script json
java script jsonjava script json
java script json
 
Json
JsonJson
Json
 
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
What is JSON? Why use JSON? JSON Types? JSON Helpful Tools?
 
JSON - Quick Overview
JSON - Quick OverviewJSON - Quick Overview
JSON - Quick Overview
 
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
 
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
 
Writing Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON SchemaWriting Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON Schema
 
Schema Design
Schema DesignSchema Design
Schema Design
 
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
 
JSON and JSON Schema in Oxygen
JSON and JSON Schema in OxygenJSON and JSON Schema in Oxygen
JSON and JSON Schema in Oxygen
 
R-Users Group JSON and ReST Introduction using Twitter
R-Users Group JSON and ReST Introduction using TwitterR-Users Group JSON and ReST Introduction using Twitter
R-Users Group JSON and ReST Introduction using Twitter
 
J s o n
J s o nJ s o n
J s o n
 
What is JSON? | JSON vs XML | Edureka
What is JSON? | JSON vs XML | EdurekaWhat is JSON? | JSON vs XML | Edureka
What is JSON? | JSON vs XML | Edureka
 
Schema
SchemaSchema
Schema
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Networkin II Estructuras con MongoDB y Javascript
Networkin II Estructuras con MongoDB y JavascriptNetworkin II Estructuras con MongoDB y Javascript
Networkin II Estructuras con MongoDB y Javascript
 
Json
JsonJson
Json
 

Similar to JSON - JavaScript Object Notation

Similar to JSON - JavaScript Object Notation (20)

Hands on JSON
Hands on JSONHands on JSON
Hands on JSON
 
Unit-2 JSON.pdf
Unit-2 JSON.pdfUnit-2 JSON.pdf
Unit-2 JSON.pdf
 
Json
JsonJson
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
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
JSON & AJAX.pptx
JSON & AJAX.pptxJSON & AJAX.pptx
JSON & AJAX.pptx
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Working with JSON.pptx
Working with JSON.pptxWorking with JSON.pptx
Working with JSON.pptx
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
 
Dealing with JSON files in python with illustrations
Dealing with JSON files in python with illustrationsDealing with JSON files in python with illustrations
Dealing with JSON files in python with illustrations
 
Java script and json
Java script and jsonJava script and json
Java script and json
 
Json at work overview and ecosystem-v2.0
Json at work   overview and ecosystem-v2.0Json at work   overview and ecosystem-v2.0
Json at work overview and ecosystem-v2.0
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
JSON
JSONJSON
JSON
 
Json
JsonJson
Json
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
JSON beautifier (1).pdf
JSON beautifier (1).pdfJSON beautifier (1).pdf
JSON beautifier (1).pdf
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
 

Recently uploaded

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 

Recently uploaded (20)

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 

JSON - JavaScript Object Notation

  • 1. JSON - Javascript Object Notation Prepared by: Ms Panda
  • 2. Selling your idea What is JSON? - JSON is a Syntax for storing and exchanging data. It’s a lightweight data-interchange format - It means Javascript Object Notation. - And it’s a text, written with Javascript Object Notation. - JSON is “self-describing” and easy to understand. Also it’s language independent since text can be read and used as a data format by any programming language.
  • 3. Selling your idea Exchanging Data? How? - When exchanging data between a browser and a server, data can only be text. - Since JSON is a text, so we can convert any javascript Object into JSON and then send off to a server.
  • 4. Selling your idea Exchanging Data? How? - Not just converting Javascript Object into JSON, we also can reverse the converting from JSON into Javascript Object. - By this way, we can work with Data as Javascript Object, with no complicated Parsing and Translating.
  • 5. Selling your idea Sending data: function login(username, pwd) { var userObject = { "name" : username, "password" : pwd } $.ajax({ url: "http://api-ams.me/v1/api/authentication", type: "POST", data: JSON.stringify(userObject), success: function(response) { console.log(“Successfully”); }, error: function(error) { console.log(“Error”); } }) }
  • 6. Selling your idea Receiving data: function loadUser(id) { $.ajax({ url: "http://api-ams.me/v1/api/users/"+id, type: "GET", success: function(response) { console.log(response.data); }, error: function(error) { console.log(“Error”); } }) }
  • 7. Selling your idea Why use JSON? - Since the JSON format is text only, it can easily be sent to and from a server as seen in example above. Besides, JSON is used as a data format by any programming language. - In Javascript, JSON.parse() is a built-in function to convert a string - written in JSON format, into native Javascript object.
  • 8. Selling your idea JSON Syntax: - The JSON syntax is a subset of the Javascript syntax. Rule: ➔ Data is in name/value pairs ➔ Data is separated by commas ➔ Curly braces hold objects ➔ Square brackets hold arrays
  • 9. Selling your idea JSON Data - A name and a value - JSON data is written as name/value pairs. A name/value pairs consists of a field name (in double quotes), followed by a colon, followed by a value: Example: "username" : "Jung" Note: JSON names required double quotes. Javascript names don’t.
  • 10. Selling your idea JSON - Evaluates to Javascript Objects - The JSON format is almost identical to Javascript objects. JSON: { "username" : "Jung" } JavaScript { username : "Jung" }
  • 11. Selling your idea JSON Value/Data Type - In JSON, values must be one of the following data types: ➔ String ➔ Number ➔ Object (JSON object) ➔ Array ➔ Boolean - In JavaScript, values can also be: ➔ Function ➔ Data ➔ Undefined
  • 12. Selling your idea JSON Data Types JSON Strings: { "username":"Jung" } JSON Numbers: { "age":28 } JSON Objects: { "data":{ "username":"Jung", "Age" : 28} } JSON Arrays: { "employees":[ "John", "Anna", "Peter" ] } JSON Boolean: { "gender":true } JSON Null: { "children":null }
  • 13. Selling your idea JSON Objects Syntax: { "name" : "value" } - JSON objects are surrounded by curly braces { }. - JSON objects are written in key/value pairs. - Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null). - Keys and values are separated by a colon. - Each key/value pair is separated by a comma.
  • 14. Selling your idea JSON Objects - Accessing Object Values - You can access the object values by using dot (.) notation: Example: var username = data.name
  • 15. Selling your idea JSON Objects - Looping an Object - You can loop thru object properties by using for-in loop: Example: user = { "name":"Jung", "age":28, "house":null }; for (x in user) { document.getElementById("demo").innerHTML += x; }
  • 16. Selling your idea JSON Files ➔ The file type for JSON files is “.json ➔ The MIME type of JSON text is “application/json” ➔ MIME - Multipurpose Internet Mail Extensions ➔ Link: https://en.wikipedia.org/wiki/MIME

Editor's Notes

  1. JSON syntax is derived from JavaScript object notation syntax:
  2. In JavaScript values can be all of the above, plus any other valid JavaScript expression, including: JSON Uses JavaScript Syntax Because JSON syntax is derived from JavaScript object notation, very little extra software is needed to work with JSON within JavaScript. With JavaScript you can create an object and assign data to it, like this: Example var person = { "name":"John", "age":31, "city":"New York" }; You can access a JavaScript object like this: Example // returns John person.name; Try it Yourself » It can also be accessed like this: Example // returns John person["name"]; Try it Yourself » Data can be modified like this: Example person.name = "Gilbert"; Try it Yourself » It can also be modified like this: Example person["name"] = "Gilbert"; Try it Yourself » You will learn how to convert JavaScript objects into JSON later in this tutorial.