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 (12)

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
Xml
baabtra.com - No. 1 supplier of quality freshers
 
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
 
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
 

Similar to Java script and json (20)

json.pptx
json.pptxjson.pptx
json.pptx
Anum Zehra
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
AnujSood25
 
Json
JsonJson
Json
krishnapriya Tadepalli
 
Json
JsonJson
Json
Sabarinath Gnanasekar
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
Jeff Fox
 
java script json
java script jsonjava script json
java script json
chauhankapil
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
Mark Daniel Dacer
 
J s o n
J s o nJ s o n
J s o n
nasifalnahian
 
Json
JsonJson
Json
Steve Fort
 
unit5_part2.pptx
unit5_part2.pptxunit5_part2.pptx
unit5_part2.pptx
jayarao21
 
Introduction to JavaScript Object Notation(JSON)
Introduction to JavaScript Object Notation(JSON)Introduction to JavaScript Object Notation(JSON)
Introduction to JavaScript Object Notation(JSON)
gaikwaddavid2022
 
CS8651 IP Unit 2 pdf regulation -2017 anna university
CS8651  IP Unit 2 pdf regulation -2017 anna universityCS8651  IP Unit 2 pdf regulation -2017 anna university
CS8651 IP Unit 2 pdf regulation -2017 anna university
amrashbhanuabdul
 
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
 
JSON Presentation.pptx JSON Presentation.pptx
JSON Presentation.pptx JSON Presentation.pptxJSON Presentation.pptx JSON Presentation.pptx
JSON Presentation.pptx JSON Presentation.pptx
trwdcn
 
JSON
JSONJSON
JSON
Zara Tariq
 
JSON in JavaScript
JSON in JavaScriptJSON in JavaScript
JSON in JavaScript
Bishrul Haq
 
JSON.pptx
JSON.pptxJSON.pptx
JSON.pptx
TilakaRt
 
Json training
Json trainingJson training
Json training
Elavarasi Dc
 
JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)
BOSS Webtech
 
Introduction to JSON
Introduction to JSONIntroduction to JSON
Introduction to JSON
Kanda Runapongsa Saikaew
 
Ad

Recently uploaded (20)

AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Ad

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