Lab 4 of 5
Β·
Guided
Load a JSON Inventory and Print Selected Fields
Objective: Use json.load() to read the devices.json file from Lab 3 and print specific fields.
Instructions
Using the devices.json file you created in Lab 3, create a file called lab4.py that loads the file and prints a summary.
Your output must match exactly:
Loaded 3 devices
sw-core-01 β 10.1.1.1
sw-access-01 β 10.1.1.2
rtr-edge-01 β 10.1.1.254
Run it with python3 lab4.py. Paste your output below and submit.
Starter Code
import json
with open("devices.json") as f:
devices = json.load(f)
print(f"Loaded {len(devices)} devices")
for device in devices:
print(f" {device['name']} β {device['ip']}")
π‘ Show Hint
Use json.load(f) inside a "with open" block. The result is a list of dicts. Access each field by key: device["name"], device["ip"].
Paste Your Output