
Json with Python
Presentation
•
Computers
•
Professional Development
•
Hard
Jeff Thuong
Used 4+ times
FREE Resource
9 Slides • 6 Questions
1
Manipulation of JSON with Python
Some text here about the topic of discussion
2
Remember what is JSON?
No problem, here is what you need to know
Reminder about JSON
JSON x Python
3
In JSON, values must be:
a string
a number
an object (JSON object)
an array
a boolean
null
JSON values cannot be one of the following data types:
a function
a date
undefined
JSON x Python
Data is stored as dictionary with the key being a string
{
"a string": "This is a string",
"a number": 1,
"a_boolean": true,
"another_boolean": false,
"nothing": null,
"an array": [1, 2, 3],
"an object": {
"name": "Jeff",
"age": 99
}
}
4
import json
JSON in Python Standard Library🎉
You can write (dump / dumps)
and read (load / loads)
JSON x Python
JSON x Python
5
dumps (... with a -s)
json.dump(obj, fp, *, skipkeys=False, ...)
Dump a JSON string of an object to an open file
with open("data.json", "w") as f:
json.dump(my_data, f)
dump
Writing
JSON x Python
json.dumps(obj, *, skipkeys=False, ...)
Dump a JSON string of an object to a string
json_repr = json.dumps(my_data)
6
loads (... with a -s)
json.load(fp, *, ...)
Load JSON data from open file
with open("data.json") as f:
data = json.load(f)
load
Reading
JSON x Python
7
Multiple Choice
Which function can READ data from
a json file opened ("with open(...) as f: ...")
json.read
json.load
json.dumps
json.loads
8
Multiple Choice
Which function can READ data from
a json stored in a string (json_string = '{"name": "jeff"}')
json.read
json.load
json.dumps
json.loads
9
Multiple Choice
Which code DOES NOT write JSON
representation of a data (e.g. a dictionary)
with open("data.json") as f:
json.dump(data, f)
with open("data.json", "w") as f: f.write(json.dumps(data))
f = open("data.json", "w")
json.dump(data, f)
10
Open VS Code, create a Jupyter Notebook and start dumping / loading JSON data
Now your turn!
11
Multiple Choice
Which data CANNOT BE dumped to JSON?
None
List
Dictionary
Tuple, like: (1, 2, 3)
Dates (datetime.datetime object)
12
Multiple Select
Which data would be different after being dumped to JSON and loaded
(SEVERAL ANSWERS POSSIBLE)?
None
Dictionary with keys different from strings
Lists with a mix of integers and strings
Tuple, like: (1, 2, 3)
13
We cannot dump this type of data in JSON
Date and Path => Error
JSON x Python
14
We can use a serializer and pass it as "default" argument.
... but data will still be a string after loading
BONUS: dumping dates
JSON x Python
15
Poll
How much do you understand handling of JSON with Python now?
Very Good
Good
So-so
Still confused
Manipulation of JSON with Python
Some text here about the topic of discussion
Show answer
Auto Play
Slide 1 / 15
SLIDE
Similar Resources on Wayground
8 questions
Intelligent Systems-Orientation
Presentation
•
University - Professi...
12 questions
Module 3 Chapter 2
Presentation
•
University
11 questions
Computer Parts and their Functions
Presentation
•
Professional Development
10 questions
Materi Pelatihan GForm 2024
Presentation
•
Professional Development
11 questions
Donor Briefing Magic
Presentation
•
Professional Development
10 questions
Quiz Java 2
Presentation
•
Professional Development
13 questions
3er Grupo Pedagógico 2025
Presentation
•
University - Professi...
11 questions
Java + SQL Unit 4
Presentation
•
University
Popular Resources on Wayground
24 questions
PBIS-HGMS Day 10
Quiz
•
6th - 8th Grade
10 questions
HCS SCI 03 Summer School Review 3
Quiz
•
3rd Grade
11 questions
Home Scope
Quiz
•
7th - 8th Grade
15 questions
HCS SCI 05 Summer School Assessment 3 Review
Quiz
•
5th Grade
35 questions
Lufkin Road Middle School Student Handbook & Policies Assessment
Quiz
•
7th Grade
18 questions
Geo 11.3 Area of Circles and Sectors
Quiz
•
9th - 11th Grade