Python Pages Doc Ic Ac Uk CPP Lessons CPP 10 Files 03 Load HTML
Python Pages Doc Ic Ac Uk CPP Lessons CPP 10 Files 03 Load HTML
The json module allows you to easily load a JSON file into its equivalent Python object (usually a dict or list).
To load your data from a JSON file, use json.load(file_object).
The following code loads the content from a file called input.json into a Python object named data. You can then
manipulate data as you would a list or dict (depending on what is in input.json)
import json
print(type(data))
To load your object directly from a JSON string rather than a file, use json.loads(string) (loads is short for ‘load
string’).
import json
The fancy term to describe this process is called deserialisation (converting a string to a data object).
Previous Next