I\'m trying to read from a json file.
This is how I created the file:
import requests
import json
import time
from pprint import pprint
BASE_URL = \
Use json.load()
(without 's') instead of json.loads()
PS You will be using json.load()
when loading from file. And json.loads()
when working with string :)
3 ways to load a json file:
import json
import ast
with open(file_path) as file:
data1 = json.load(file)
data2 = json.loads(file.read())
data3 = ast.literal_eval(file.read())
You should use json.load whenever possible, but sometimes the JSON file is not strictly in the correct format (e.g. single quotes instead of double quotes). A solution is to use ast.literal_eval().
json.load()
is for loading a file. json.loads()
works with strings.