# Prepare list of dictionaries for Json
people = [
{"name": "Alice", "age": 30, "occupation": "Engineer"},
{"name": "Bob", "age": 25, "occupation": "Designer"},
{"name": "Charlie", "age": 22, "occupation": "Student"}
]
# Use json module to convert list to JSON format
import json
json_string = json.dumps(people, indent=2) # Indentation for readability
# Save json string to file
with open("people.json", "w") as json_file:
json_file.write(json_string)
1. Create
JSON
JSON
file we get is :2. Access certain items in JSON
Bob
inpeople.json
:people[1]["name"]
,people[1]
select the second dictionary and["name"]
is the key for this dictionary3. Display
JSON
in jupyterRunning this code will display the JSON data in the output of a notebook cell.