SlideShare a Scribd company logo
1 of 19
25-Mar-24
JSON
Outline
 What is JSON?
 Syntax
 Example
 Schema
 Validating JSON file
 Using JSON with Python
 Writing a JSON file
 Reading a JSON
 Accessing JSON Properties in Python
What is JSON?
 “JSON” stands for “JavaScript Object Notation”
 Lightweight data-interchange format
 Despite the name, JSON is a (mostly) language-
independent way of specifying objects as name-value
pairs
 Structured representation of data object
 Can be parsed with most modern languages
 JSON Schema can be used to validated a JSON
file
JSON Syntax Rules
 JSON is almost identical to python dictionary except for
 In JSON, true and false are not capitalized
 In JSON, null is used instead of None
 Uses key/value pairs: {“name”: “John”}
 Uses double quotes around KEY and VALUE
 Must use the specified types
 File type is “.json”
 A value can be: A string, a number, true, false, null, an
object, or an array
 Strings are enclosed in double quotes, and can contain
the usual assortment of escaped characters
JSON Example
{
"name": "John Smith",
"age": 35,
"address": {
"street": "5 main St.",
"city": "Austin"
},
"children": ["Mary", "Abel"]
}
JSON Schema
 A JSON Schema allows you to specify what type of
data can go into your JSON files.
 It allows you to restrict the type of data entered.
JSON Schema
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
},
"address": {
"type": "object",
"properties": {
"street": {
"type": "string"
},
"city": {
"type": "string"
}
}
"children": {
"type": "array",
"items": {
"type": "string
}
}
}
}
Validating JSON file
 The following website can be used to validate a JSON
file against a schema
https://www.jsonschemavalidator.net/
 Paste both the schema and the corresponding JSON file
Using JSON with Python
 To work with JSON (string, or file containing JSON
object), you can use Python's json module.
import json
Loading JSON data from a file
 Example:
def load_json(filename):
with open(filename) as file:
jsn = json.load(file)
#file.close()
return jsn
person = load_json('person.json')
 This command parse the above person.json using
json.load() method from the json module. The result is a
Python dictionary.
Writing JSON object to a file
 Example:
person = { "name": "John Smith", "age": 35,
"address": {"street": "5 main St.", "city":
"Austin"}, "children": ["Mary", "Abel"]}
with open('person_to_json.json', 'w') as fp:
json.dump(person, fp, indent=4)
 Using json.dump(), we can convert Python Objects to
JSON file.
Accessing JSON Properties in Python
 Example:
Assume that you already loaded your person.json as
follows.
person = load_json('person.json')
To access the property "name"
 Print(person["name"])
 John Smith
Accessing JSON Properties in Python
 Example:
Assume that you already loaded your person.json as
follows.
person = load_json('person.json')
To access the property “age"
 person["age"]
 35
Accessing JSON Properties in Python
 Example:
Assume that you already loaded your person.json as
follows.
person = load_json('person.json')
To access the property “street"
 print(person["address"]["street"])
 5 main St.
Accessing JSON Properties in Python
 Example:
Assume that you already loaded your person.json as
follows.
person = load_json('person.json')
To access the property “street"
 print(person["address"]["city"])
 Austin
Accessing JSON Properties in Python
 Example:
Assume that you already loaded your person.json as
follows.
person = load_json('person.json')
To access the property “street"
 print(person["children"][0])
 Mary
Accessing JSON Properties in Python
 Example:
Assume that you already loaded your person.json as
follows.
person = load_json('person.json')
To access the property “street"
 print(person["children"][1])
 Abel
Python – JSON Objects
Credit:
 https://www.youtube.com/watch?v=wI1CWzNtE-M
 https://www.programiz.com/python-programming/json

More Related Content

Similar to JSON(JavaScript Object Notation) Presentation transcript

Similar to JSON(JavaScript Object Notation) Presentation transcript (20)

JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)JSON Data Parsing in Snowflake (By Faysal Shaarani)
JSON Data Parsing in Snowflake (By Faysal Shaarani)
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
Working with JSON.pptx
Working with JSON.pptxWorking with JSON.pptx
Working with JSON.pptx
 
Json
JsonJson
Json
 
JSON & AJAX.pptx
JSON & AJAX.pptxJSON & AJAX.pptx
JSON & AJAX.pptx
 
Hands on JSON
Hands on JSONHands on JSON
Hands on JSON
 
All about XML, JSON and related topics..
All about XML, JSON and related topics..All about XML, JSON and related topics..
All about XML, JSON and related topics..
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
JSON.pptx
JSON.pptxJSON.pptx
JSON.pptx
 
Json
JsonJson
Json
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
 
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
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
Introduction to JSON
Introduction to JSONIntroduction to JSON
Introduction to JSON
 
JSON - JavaScript Object Notation
JSON - JavaScript Object NotationJSON - JavaScript Object Notation
JSON - JavaScript Object Notation
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
 
JSON.pptx
JSON.pptxJSON.pptx
JSON.pptx
 
Java Script Object Notation (JSON)
Java Script Object Notation (JSON)Java Script Object Notation (JSON)
Java Script Object Notation (JSON)
 
JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12
 

Recently uploaded

VIP Kolkata Call Girl Lake Gardens 👉 8250192130 Available With Room
VIP Kolkata Call Girl Lake Gardens 👉 8250192130  Available With RoomVIP Kolkata Call Girl Lake Gardens 👉 8250192130  Available With Room
VIP Kolkata Call Girl Lake Gardens 👉 8250192130 Available With Roomdivyansh0kumar0
 
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackVIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackSuhani Kapoor
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxGry Tina Tinde
 
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackVIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackSuhani Kapoor
 
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...Suhani Kapoor
 
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...Suhani Kapoor
 
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call GirlsDelhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girlsshivangimorya083
 
do's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Jobdo's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of JobRemote DBA Services
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...Suhani Kapoor
 
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...gurkirankumar98700
 
Sonam +91-9537192988-Mind-blowing skills and techniques of Ahmedabad Call Girls
Sonam +91-9537192988-Mind-blowing skills and techniques of Ahmedabad Call GirlsSonam +91-9537192988-Mind-blowing skills and techniques of Ahmedabad Call Girls
Sonam +91-9537192988-Mind-blowing skills and techniques of Ahmedabad Call GirlsNiya Khan
 
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...Suhani Kapoor
 
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
Call Girl in Low Price Delhi Punjabi Bagh  9711199012Call Girl in Low Price Delhi Punjabi Bagh  9711199012
Call Girl in Low Price Delhi Punjabi Bagh 9711199012sapnasaifi408
 
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
Production Day 1.pptxjvjbvbcbcb bj bvcbj
Production Day 1.pptxjvjbvbcbcb bj bvcbjProduction Day 1.pptxjvjbvbcbcb bj bvcbj
Production Day 1.pptxjvjbvbcbcb bj bvcbjLewisJB
 
VIP Call Girls Service Cuttack Aishwarya 8250192130 Independent Escort Servic...
VIP Call Girls Service Cuttack Aishwarya 8250192130 Independent Escort Servic...VIP Call Girls Service Cuttack Aishwarya 8250192130 Independent Escort Servic...
VIP Call Girls Service Cuttack Aishwarya 8250192130 Independent Escort Servic...Suhani Kapoor
 
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳anilsa9823
 
Internshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateInternshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateSoham Mondal
 
定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
 定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一 定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一Fs sss
 

Recently uploaded (20)

VIP Kolkata Call Girl Lake Gardens 👉 8250192130 Available With Room
VIP Kolkata Call Girl Lake Gardens 👉 8250192130  Available With RoomVIP Kolkata Call Girl Lake Gardens 👉 8250192130  Available With Room
VIP Kolkata Call Girl Lake Gardens 👉 8250192130 Available With Room
 
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackVIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptx
 
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackVIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
 
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
 
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
 
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call GirlsDelhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
 
do's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Jobdo's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Job
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
 
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
(Call Girls) in Lucknow Real photos of Female Escorts 👩🏼‍❤️‍💋‍👩🏻 8923113531 ➝...
 
Sonam +91-9537192988-Mind-blowing skills and techniques of Ahmedabad Call Girls
Sonam +91-9537192988-Mind-blowing skills and techniques of Ahmedabad Call GirlsSonam +91-9537192988-Mind-blowing skills and techniques of Ahmedabad Call Girls
Sonam +91-9537192988-Mind-blowing skills and techniques of Ahmedabad Call Girls
 
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
 
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
Call Girl in Low Price Delhi Punjabi Bagh  9711199012Call Girl in Low Price Delhi Punjabi Bagh  9711199012
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
 
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
Call Girls In Bhikaji Cama Place 24/7✡️9711147426✡️ Escorts Service
 
Production Day 1.pptxjvjbvbcbcb bj bvcbj
Production Day 1.pptxjvjbvbcbcb bj bvcbjProduction Day 1.pptxjvjbvbcbcb bj bvcbj
Production Day 1.pptxjvjbvbcbcb bj bvcbj
 
VIP Call Girls Service Cuttack Aishwarya 8250192130 Independent Escort Servic...
VIP Call Girls Service Cuttack Aishwarya 8250192130 Independent Escort Servic...VIP Call Girls Service Cuttack Aishwarya 8250192130 Independent Escort Servic...
VIP Call Girls Service Cuttack Aishwarya 8250192130 Independent Escort Servic...
 
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
 
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCeCall Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
 
Internshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateInternshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University Certificate
 
定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
 定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一 定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
定制(UOIT学位证)加拿大安大略理工大学毕业证成绩单原版一比一
 

JSON(JavaScript Object Notation) Presentation transcript

  • 2. Outline  What is JSON?  Syntax  Example  Schema  Validating JSON file  Using JSON with Python  Writing a JSON file  Reading a JSON  Accessing JSON Properties in Python
  • 3. What is JSON?  “JSON” stands for “JavaScript Object Notation”  Lightweight data-interchange format  Despite the name, JSON is a (mostly) language- independent way of specifying objects as name-value pairs  Structured representation of data object  Can be parsed with most modern languages  JSON Schema can be used to validated a JSON file
  • 4. JSON Syntax Rules  JSON is almost identical to python dictionary except for  In JSON, true and false are not capitalized  In JSON, null is used instead of None  Uses key/value pairs: {“name”: “John”}  Uses double quotes around KEY and VALUE  Must use the specified types  File type is “.json”  A value can be: A string, a number, true, false, null, an object, or an array  Strings are enclosed in double quotes, and can contain the usual assortment of escaped characters
  • 5. JSON Example { "name": "John Smith", "age": 35, "address": { "street": "5 main St.", "city": "Austin" }, "children": ["Mary", "Abel"] }
  • 6. JSON Schema  A JSON Schema allows you to specify what type of data can go into your JSON files.  It allows you to restrict the type of data entered.
  • 7. JSON Schema { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer" }, "address": { "type": "object", "properties": { "street": { "type": "string" }, "city": { "type": "string" } } "children": { "type": "array", "items": { "type": "string } } } }
  • 8. Validating JSON file  The following website can be used to validate a JSON file against a schema https://www.jsonschemavalidator.net/  Paste both the schema and the corresponding JSON file
  • 9. Using JSON with Python  To work with JSON (string, or file containing JSON object), you can use Python's json module. import json
  • 10. Loading JSON data from a file  Example: def load_json(filename): with open(filename) as file: jsn = json.load(file) #file.close() return jsn person = load_json('person.json')  This command parse the above person.json using json.load() method from the json module. The result is a Python dictionary.
  • 11. Writing JSON object to a file  Example: person = { "name": "John Smith", "age": 35, "address": {"street": "5 main St.", "city": "Austin"}, "children": ["Mary", "Abel"]} with open('person_to_json.json', 'w') as fp: json.dump(person, fp, indent=4)  Using json.dump(), we can convert Python Objects to JSON file.
  • 12. Accessing JSON Properties in Python  Example: Assume that you already loaded your person.json as follows. person = load_json('person.json') To access the property "name"  Print(person["name"])  John Smith
  • 13. Accessing JSON Properties in Python  Example: Assume that you already loaded your person.json as follows. person = load_json('person.json') To access the property “age"  person["age"]  35
  • 14. Accessing JSON Properties in Python  Example: Assume that you already loaded your person.json as follows. person = load_json('person.json') To access the property “street"  print(person["address"]["street"])  5 main St.
  • 15. Accessing JSON Properties in Python  Example: Assume that you already loaded your person.json as follows. person = load_json('person.json') To access the property “street"  print(person["address"]["city"])  Austin
  • 16. Accessing JSON Properties in Python  Example: Assume that you already loaded your person.json as follows. person = load_json('person.json') To access the property “street"  print(person["children"][0])  Mary
  • 17. Accessing JSON Properties in Python  Example: Assume that you already loaded your person.json as follows. person = load_json('person.json') To access the property “street"  print(person["children"][1])  Abel
  • 18. Python – JSON Objects