10.2 JSON and Python
Python and JSON together form a dream team. To process JSON documents, you must import the json module. This module comes with Python by default and does not need to be installed separately. The module provides the following functions:
-
load(filehandle)This function reads a text file previously opened via open and returns the JSON data it contains as Python dictionaries and lists.
-
loads(str)In the sense of load string, this function expects the JSON document in the string passed as parameter.
-
dump(obj, filehandle)This function stores the Python object passed in the first parameter as a JSON string in the specified file. Some additional parameters allow you to influence the resulting JSON document. indent=2 specifies ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access