A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
python3 -c "import json, urllib.request; data = json.loads(urllib.request.urlopen('https://sandboxdnac.cisco.com').read())"
JSON is the language of modern APIs. Every controller, every REST API, every network automation framework uses it. If you can read and write JSON, you can automate networks. If you can't, every API interaction becomes a chore. This lesson closes that gap.
{"device": {"hostname": "sw1.example.com","managementIpAddress": "10.10.20.10","platformId": "C9300-48P","upTime": "42 days, 3:15:42","softwareVersion": "17.9.4a","interfaces": [{"name": "GigabitEthernet0/1","status": "up","vlan": 10},{"name": "GigabitEthernet0/2","status": "up","vlan": 20},{"name": "GigabitEthernet0/3","status": "down","vlan": 10}]}}
That structure shows all the pieces: objects at the top level, nested objects (device), an array of interfaces, and mixed primitive types. Reading JSON is about navigating this hierarchy — following keys through nested objects and iterating through arrays.
import jsonimport urllib.request# Fetch JSON from an APIdef get_devices():url = 'https://sandboxdnac.cisco.com/dna/intent/api/v1/network-device'req = urllib.request.Request(url, headers={'X-Auth-Token': 'your_token_here'})with urllib.request.urlopen(req) as response:data = json.loads(response.read())return data# Navigate the structuredata = get_devices()for device in data['response']:hostname = device['hostname']ip = device['managementIpAddress']version = device['softwareVersion']print(f'{hostname} ({ip}) - {version}')# Filter devices by versionoutdated = [d for d in data['response'] if d['softwareVersion'].startswith('16.')]print(f'Found {len(outdated)} outdated devices')
`json.loads()` converts a JSON string to a Python dictionary. From there, all normal Python operations work: indexing, iterating, list comprehensions, filtering. The impedance mismatch between JSON and Python data structures is nearly zero — which is why Python is the dominant language for network automation.
Python dictionaries and JSON objects are essentially the same. Python lists and JSON arrays are the same. Python strings/numbers/booleans/null map directly to JSON primitives. This is why you can convert back and forth with `json.loads()` and `json.dumps()` without thinking about types. If you know Python data structures, you know JSON.
Finish the lesson once you have worked through the material. This awards ★ 115 XP.
Write a function that takes a list of device dictionaries and returns only those matching a given platform ID.