The function json.load() reads the JSON data from a file and returns a Python object while the function json.loads() reads JSON data from a string and returns a Python object.
In other words, json.load() is used when you want to read data from a file (using a file object), whereas json.loads() is used when you want to parse a JSON-formatted string.
For example:
import json
# Load JSON data from a file
with open('data.json') as f:
data = json.load(f)
# Parse JSON-formatted string
json_string = '{"name": "John", "age": 30}'
data = json.loads(json_string)
Asked: 2021-09-26 11:00:00 +0000
Seen: 11 times
Last updated: May 20 '22