June 2019
Beginner to intermediate
770 pages
19h 24m
English
When we write JSON files, we generally do something like this:
from pathlib import Pathwith Path("temp.json").open("w", encoding="UTF-8") as target:
json.dump(travel3, target, default=blog_j2_encode)
We open the file with the required encoding. We provide the file object to the json.dump() method. When we read JSON files, we will use a similar technique:
from pathlib import Pathwith Path("some_source.json").open(encoding="UTF-8") as source: objects = json.load(source, object_hook=blog_decode)
The idea is to segregate the JSON representation as text from any conversion to bytes on the resulting file. There are a few formatting options that are available in JSON. We've shown you an indent of four spaces because that seems ...
Read now
Unlock full access