SlideShare a Scribd company logo
JavaScript and JSON
Front end development tool
Overview
• Required knowledge before working with JS and JSON
• What is JSON?
• Why use JSON?
• JSON vs XML
• Syntax
• Data Types
• Usage
• Simple example
What you should know before working with
JavaScript and JSON.
• JavaScript and JSON is not for a beginner
• JSON is that it is a conversation that happens between
your server and your browser.
• You should be familiar with building online projects and
know how HTML works.
What is JSON?
JSON is ( JavaScript Object Notation ).
• Format for sharing data.
• Derived from JavaScript.
• Language independent
• An alternative to XML
What is JSON?
JSON is NOT ..
• Overly Complex
• A “document” format
• A markup language
• A programming language
Why use JSON?
• Easy to read
Advantage
var person = {
"name":"John",
"age":30,
"attendance":true,
"car":null
}
Why use JSON?
• Easy to parse
Advantage
var person = {
"name":"John",
"age":30,
"attendance":true,
"car":null
}
// returns John
person.name;
Why use JSON?
• Leaner than XML
Advantage
var person = {
"name":"John",
"age":30,
"attendance":true,
"car":null
}
<persons>
<person>
<name>John</name>
<age>30</age>
</person>
</persons>
Why use JSON?
• Easy to read
• Easy to parse
Advantage
• Leaner than XML
• Supported by all major JavaScript frameworks
• Supported by most backend technologies
JSON vs XML
• Self describing, human readable.
• Hierarchical (values within values)
• Can be parsed and used by lots of programming languages
Much like XML
JSON vs XML
• JSON doesn't use end tag
• JSON is shorter
Not like XML
• JSON is quicker to read and write
• JSON can use arrays
Syntax
• Unordered sets of name/value pairs
• Begins with { (left brace)
• Each name is followed by : (colon)
• Name/value pairs are separated by , (comma)
• Ends with } (right brace)
Syntax
var person = {
"name":"John",
"age":30,
"attendance":true,
"car":null
}
JSON Example
Syntax
Arrays in JSON
• An ordered collection of values
• Begins with [ (left bracket)
• Name/value pairs are separated by , (comma)
• Ends with ] (right bracket)
Syntax
var person = {
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat" ]
}
JSON Array Example
Data Types
• A String
• A Number
• An Array
• An Object (JSON object)
In JSON, values must be one of the following data types:
• A Boolean
• Null
Data Types
Strings in JSON must be written in double quotes.
JSON String
{ "name":"John" }
Numbers in JSON must be an integer or a floating point.
JSON Numbers
{ "age":30 }
Data Types
Objects as values in JSON must follow the same rules as JSON objects.
JSON Objects
{
"employee":{ "name":"John", "age":30, "city":"New
York" }
}
Values in JSON can be arrays.
JSON Arrays
{
"employees":[ "John", "Anna", "Peter" ]
}
Data Types
Values in an array can also be another array, or even
another JSON object:
JSON Arrays
employee = {
"name":"John",
"age":30,
"cars": [
{ "name":"Ford", "models":[ "Fiesta", "Focus"] },
{ "name":"BMW", "models":[ "320", "X3", "X5" ] },
{ "name":"Fiat", "models":[ "500", "Panda" ] }
]
}
Data Types
• JSON Objects: Unordered key/value pairs wrapped in { }
• JSON Arrays: Ordered key/value pairs wrapped in [ ]
• Each key/value pair is separated by a comma (,).
• Keys and values are separated by a colon (:).
Object & Array
• Keys must be strings, and values must be a valid JSON
data type (string, number, object, array, boolean or
null).
Data Types
Values in JSON can be true/false.
JSON Booleans
{ "sale":true }
Values in JSON can be null.
JSON null
{ "middlename":null }
Usage
Anywhere and everywhere!
eTime
Simple example
Parsing JSON
Imagine we received this text from a web server:
'{ "name":"John", "age":30, "city":"New York"}'
Use the JavaScript function JSON.parse() to convert text into a
JavaScript object:
var obj = JSON.parse('{ "name":"John", "age":30,
"city":"New York"}');
Recourses
https://www.w3schools.com/js/js_json.asp
The JSON basics course for Jeff Fox
Javascript and JSON course for Ray Villalobos
Islam Abdelzaher ...

More Related Content

What's hot

Jumpstart: Introduction to Schema Design
Jumpstart: Introduction to Schema DesignJumpstart: Introduction to Schema Design
Jumpstart: Introduction to Schema Design
MongoDB
 
Top JSON Interview Questions for Freshers
Top JSON Interview Questions for FreshersTop JSON Interview Questions for Freshers
Top JSON Interview Questions for Freshers
Hitesh Kumar
 
Back to Basics 1: Thinking in documents
Back to Basics 1: Thinking in documentsBack to Basics 1: Thinking in documents
Back to Basics 1: Thinking in documents
MongoDB
 
Schema Design
Schema Design Schema Design
Schema Design
MongoDB
 
Schema Design
Schema DesignSchema Design
Schema Design
MongoDB
 
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
Yos Riady
 
Jumpstart: Schema Design
Jumpstart: Schema DesignJumpstart: Schema Design
Jumpstart: Schema Design
MongoDB
 
Schema Design
Schema DesignSchema Design
Schema Design
MongoDB
 
ETL into Neo4j
ETL into Neo4jETL into Neo4j
ETL into Neo4j
Max De Marzi
 
Document Oriented Access to Graphs
Document Oriented Access to GraphsDocument Oriented Access to Graphs
Document Oriented Access to Graphs
Neo4j
 
Simple MongoDB design for Rails apps
Simple MongoDB design for Rails appsSimple MongoDB design for Rails apps
Simple MongoDB design for Rails apps
Sérgio Santos
 
Xml
XmlXml

What's hot (12)

Jumpstart: Introduction to Schema Design
Jumpstart: Introduction to Schema DesignJumpstart: Introduction to Schema Design
Jumpstart: Introduction to Schema Design
 
Top JSON Interview Questions for Freshers
Top JSON Interview Questions for FreshersTop JSON Interview Questions for Freshers
Top JSON Interview Questions for Freshers
 
Back to Basics 1: Thinking in documents
Back to Basics 1: Thinking in documentsBack to Basics 1: Thinking in documents
Back to Basics 1: Thinking in documents
 
Schema Design
Schema Design Schema Design
Schema Design
 
Schema Design
Schema DesignSchema Design
Schema Design
 
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
 
Jumpstart: Schema Design
Jumpstart: Schema DesignJumpstart: Schema Design
Jumpstart: Schema Design
 
Schema Design
Schema DesignSchema Design
Schema Design
 
ETL into Neo4j
ETL into Neo4jETL into Neo4j
ETL into Neo4j
 
Document Oriented Access to Graphs
Document Oriented Access to GraphsDocument Oriented Access to Graphs
Document Oriented Access to Graphs
 
Simple MongoDB design for Rails apps
Simple MongoDB design for Rails appsSimple MongoDB design for Rails apps
Simple MongoDB design for Rails apps
 
Xml
XmlXml
Xml
 

Similar to Java script and json

Json
JsonJson
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
Mark Daniel Dacer
 
JSON beautifier (1).pdf
JSON beautifier (1).pdfJSON beautifier (1).pdf
JSON beautifier (1).pdf
json beautifier
 
Hands on JSON
Hands on JSONHands on JSON
Hands on JSON
Octavian Nadolu
 
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
Boulder Java User's Group
 
JSON - JavaScript Object Notation
JSON - JavaScript Object NotationJSON - JavaScript Object Notation
JSON - JavaScript Object Notation
Sothearin Ren
 
java script json
java script jsonjava script json
java script json
chauhankapil
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
Rafael Montesinos Muñoz
 
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
Ruby Meditation
 
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
 
Json
JsonJson
Json
soumya
 
NAVTechDays 2017 Json Meets NAV
NAVTechDays 2017 Json Meets NAVNAVTechDays 2017 Json Meets NAV
NAVTechDays 2017 Json Meets NAV
Gunnar Gestsson
 
JSON.pptx
JSON.pptxJSON.pptx
JSON.pptx
TilakaRt
 
JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12
Jitendra Zaa
 
JSON
JSONJSON
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
 
JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)
BOSS Webtech
 
Introducing Azure DocumentDB - NoSQL, No Problem
Introducing Azure DocumentDB - NoSQL, No ProblemIntroducing Azure DocumentDB - NoSQL, No Problem
Introducing Azure DocumentDB - NoSQL, No Problem
Andrew Liu
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
Skillwise Group
 
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
 

Similar to Java script and json (20)

Json
JsonJson
Json
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
JSON beautifier (1).pdf
JSON beautifier (1).pdfJSON beautifier (1).pdf
JSON beautifier (1).pdf
 
Hands on JSON
Hands on JSONHands on JSON
Hands on 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
 
JSON - JavaScript Object Notation
JSON - JavaScript Object NotationJSON - JavaScript Object Notation
JSON - JavaScript Object Notation
 
java script json
java script jsonjava script json
java script json
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
 
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
JsonJson
Json
 
NAVTechDays 2017 Json Meets NAV
NAVTechDays 2017 Json Meets NAVNAVTechDays 2017 Json Meets NAV
NAVTechDays 2017 Json Meets NAV
 
JSON.pptx
JSON.pptxJSON.pptx
JSON.pptx
 
JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12
 
JSON
JSONJSON
JSON
 
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
 
JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)
 
Introducing Azure DocumentDB - NoSQL, No Problem
Introducing Azure DocumentDB - NoSQL, No ProblemIntroducing Azure DocumentDB - NoSQL, No Problem
Introducing Azure DocumentDB - NoSQL, No Problem
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
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
 

Recently uploaded

AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
maazsz111
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 

Recently uploaded (20)

AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 

Java script and json

  • 1. JavaScript and JSON Front end development tool
  • 2. Overview • Required knowledge before working with JS and JSON • What is JSON? • Why use JSON? • JSON vs XML • Syntax • Data Types • Usage • Simple example
  • 3. What you should know before working with JavaScript and JSON. • JavaScript and JSON is not for a beginner • JSON is that it is a conversation that happens between your server and your browser. • You should be familiar with building online projects and know how HTML works.
  • 4. What is JSON? JSON is ( JavaScript Object Notation ). • Format for sharing data. • Derived from JavaScript. • Language independent • An alternative to XML
  • 5. What is JSON? JSON is NOT .. • Overly Complex • A “document” format • A markup language • A programming language
  • 6. Why use JSON? • Easy to read Advantage var person = { "name":"John", "age":30, "attendance":true, "car":null }
  • 7. Why use JSON? • Easy to parse Advantage var person = { "name":"John", "age":30, "attendance":true, "car":null } // returns John person.name;
  • 8. Why use JSON? • Leaner than XML Advantage var person = { "name":"John", "age":30, "attendance":true, "car":null } <persons> <person> <name>John</name> <age>30</age> </person> </persons>
  • 9. Why use JSON? • Easy to read • Easy to parse Advantage • Leaner than XML • Supported by all major JavaScript frameworks • Supported by most backend technologies
  • 10. JSON vs XML • Self describing, human readable. • Hierarchical (values within values) • Can be parsed and used by lots of programming languages Much like XML
  • 11. JSON vs XML • JSON doesn't use end tag • JSON is shorter Not like XML • JSON is quicker to read and write • JSON can use arrays
  • 12. Syntax • Unordered sets of name/value pairs • Begins with { (left brace) • Each name is followed by : (colon) • Name/value pairs are separated by , (comma) • Ends with } (right brace)
  • 13. Syntax var person = { "name":"John", "age":30, "attendance":true, "car":null } JSON Example
  • 14. Syntax Arrays in JSON • An ordered collection of values • Begins with [ (left bracket) • Name/value pairs are separated by , (comma) • Ends with ] (right bracket)
  • 15. Syntax var person = { "name":"John", "age":30, "cars":[ "Ford", "BMW", "Fiat" ] } JSON Array Example
  • 16. Data Types • A String • A Number • An Array • An Object (JSON object) In JSON, values must be one of the following data types: • A Boolean • Null
  • 17. Data Types Strings in JSON must be written in double quotes. JSON String { "name":"John" } Numbers in JSON must be an integer or a floating point. JSON Numbers { "age":30 }
  • 18. Data Types Objects as values in JSON must follow the same rules as JSON objects. JSON Objects { "employee":{ "name":"John", "age":30, "city":"New York" } } Values in JSON can be arrays. JSON Arrays { "employees":[ "John", "Anna", "Peter" ] }
  • 19. Data Types Values in an array can also be another array, or even another JSON object: JSON Arrays employee = { "name":"John", "age":30, "cars": [ { "name":"Ford", "models":[ "Fiesta", "Focus"] }, { "name":"BMW", "models":[ "320", "X3", "X5" ] }, { "name":"Fiat", "models":[ "500", "Panda" ] } ] }
  • 20. Data Types • JSON Objects: Unordered key/value pairs wrapped in { } • JSON Arrays: Ordered key/value pairs wrapped in [ ] • Each key/value pair is separated by a comma (,). • Keys and values are separated by a colon (:). Object & Array • Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null).
  • 21. Data Types Values in JSON can be true/false. JSON Booleans { "sale":true } Values in JSON can be null. JSON null { "middlename":null }
  • 23. Simple example Parsing JSON Imagine we received this text from a web server: '{ "name":"John", "age":30, "city":"New York"}' Use the JavaScript function JSON.parse() to convert text into a JavaScript object: var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
  • 24. Recourses https://www.w3schools.com/js/js_json.asp The JSON basics course for Jeff Fox Javascript and JSON course for Ray Villalobos