Instruction
Good job! Here's what we learned in this part.
- You can read JSON files into Python using the built-in
jsonpackage:import json
- You can load a JSON file into memory using
json.load():with open('users_names.json', 'r') as file: users = json.load(file) - JSON objects are loaded as dictionaries, while JSON arrays are loaded as Python lists. Strings are loaded as Python strings, numbers as Python numbers, logical values as the corresponding logical values in Python, and
nullasNone. - Nested JSON objects become nested Python dictionaries.
- You can load data from a JSON string using
json.loads():json_string = '[{"first_name": "Guido", "last_name":"Rossum"}, {"first_name": "Alfred", "last_name":"Hitchcock"}]' parsed_json = json.loads(json_string)
Before we move on to the next section, let's do two more exercises!
Exercise
Click to begin the quiz.



