
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
10 questions
Materi pemahaman peserta didik
Presentation
•
Professional Development
10 questions
Planets
Presentation
•
Professional Development
11 questions
Robotics
Presentation
•
University
8 questions
GO! quizizz zeriuz day 4
Presentation
•
Professional Development
12 questions
PENGINDRAAN JAUH
Presentation
•
KG
15 questions
Y1 ICT Topic: Inserting Online Pictures in the Spreadsheet
Presentation
•
KG
15 questions
HTML Forms
Presentation
•
Professional Development
7 questions
Pelatihan FPD
Presentation
•
KG
Popular Resources on Wayground
28 questions
US History Regents Review
Quiz
•
11th Grade
36 questions
Biology Regents Review
Quiz
•
9th - 10th Grade
20 questions
Math Review
Quiz
•
3rd Grade
38 questions
Regents Life Science General Review
Quiz
•
9th Grade
20 questions
Math Review
Quiz
•
6th Grade
21 questions
EOY Grade 6 Benchmark Assessment - Content Skills
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade