
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
15 questions
Computers and Devices
Presentation
•
KG - University
8 questions
SILABUS INFORMATIKA SMP
Presentation
•
Professional Development
10 questions
Chapter 9 Lecture 1 & 2
Presentation
•
University
10 questions
Model matter, for 5th (recap of atoms, molecules and compunds)
Presentation
•
1st - 3rd Grade
11 questions
WRITTEN COMMUNICATION
Presentation
•
Professional Development
10 questions
C++ User Input
Presentation
•
University
12 questions
Intro to Thermochemistry
Presentation
•
10th Grade
11 questions
Site Assessment Tool
Presentation
•
Professional Development
Popular Resources on Wayground
15 questions
Grade 3 Simulation Assessment 1
Quiz
•
3rd Grade
22 questions
HCS Grade 4 Simulation Assessment_1 2526sy
Quiz
•
4th Grade
16 questions
Grade 3 Simulation Assessment 2
Quiz
•
3rd Grade
19 questions
HCS Grade 5 Simulation Assessment_1 2526sy
Quiz
•
5th Grade
17 questions
HCS Grade 4 Simulation Assessment_2 2526sy
Quiz
•
4th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
24 questions
HCS Grade 5 Simulation Assessment_2 2526sy
Quiz
•
5th Grade
20 questions
Math Review
Quiz
•
3rd Grade