JSON

JSON

import json # parse JSON as object json_string = '{"name": "John", "age": 30, "city": "New York"}' python_dict = json.loads(json_string) print(python_dict["name"]) # Output: John # read JSON from file object import json with open('data.json', 'r') as f: python_dict = json.load(f) print(python_dict["age"])

Caveat

You can only read the body of the response ONCE.

  • e.g. .json() and .text()

Be intentional where you place the body read method like .json() in the fetch chain.

If you attempt to read the data multiple times, it will read to Already read error.