Loading and exploring a JSON
Now that you know what a JSON is, you'll load one into your Python
environment and explore it yourself. Herein, you'll load the JSON
'a_movie.json' into the variable json_data, which will be a
dictionary. You'll then explore the JSON contents by printing the
key-value pairs of json_data to the shell.
This exercise is part of the course
Importing Data in Python
Exercise instructions
- Load the JSON
'a_movie.json'into the variablejson_datawithin the context provided by thewithstatement. - Use a
forloop to print all key-value pairs in the dictionaryjson_data.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load JSON: json_data
with open("a_movie.json") as json_file:
____
# Print each key-value pair in json_data
for k in ____:
print(k + ': ', ____)