Lab 3 of 5
Β·
Semi-Guided
Save a Device Inventory to a JSON File
Objective: Use json.dump() to write a list of device dictionaries to a JSON file.
Instructions
Create a file called lab3.py. Save the following device inventory to a file called devices.json using json.dump() with indent=2. Then print a confirmation message and the name of the first device.
devices = [
{"name": "sw-core-01", "ip": "10.1.1.1", "site": "HQ"},
{"name": "sw-access-01","ip": "10.1.1.2", "site": "HQ"},
{"name": "rtr-edge-01", "ip": "10.1.1.254", "site": "HQ"},
]
Your output must match exactly:
Saved 3 devices to devices.json
First device: sw-core-01
Run it with python3 lab3.py. Paste your output below and submit.
π‘ Show Hint
Use json.dump(devices, f, indent=2) inside a "with open" block. After saving, print the confirmation using len(devices) and devices[0]["name"].
Paste Your Output