6.7 Recognize the building blocks of JSON data
CCNA 200-301 v1.1 · 6.0 Automation and Programmability
JSON is the data format of REST APIs and of most automation tools. It is plain text built from just two structures, objects and arrays, holding strings, numbers, booleans and null. For the CCNA you read a JSON document, find values in it, and spot invalid JSON.
What you must know
- Name JSON's structures: objects
{}with key/value pairs and arrays[]of values. - Name the value types: string, number, boolean, null, object, array.
- Find a value by following keys and indexes.
- Spot common mistakes: single quotes, trailing commas, unquoted keys, comments.
Objects, arrays and values
{
"hostname": "SW1",
"managementIp": "10.99.0.11",
"reachable": true,
"uptimeDays": 41,
"location": null,
"interfaces": [
{"name": "GigabitEthernet0/1", "vlan": 10, "enabled": true},
{"name": "GigabitEthernet0/2", "vlan": 20, "enabled": false}
]
}| Type | Example | Rule |
|---|---|---|
| String | "SW1" | Double quotes only |
| Number | 41, 3.5 | No quotes |
| Boolean | true, false | Lower case, no quotes |
| Null | null | No value |
| Object | {"key": value} | Keys are strings in double quotes |
| Array | [1, 2, 3] | Ordered list, any types |
To read the VLAN of the second interface, follow the path interfaces → index 1 (arrays count from 0) → vlan: the answer is 20. In Python that is data["interfaces"][1]["vlan"].
Where JSON travels
The same format carries the change to the device (1) and the data back from it (2). Whitespace and line breaks do not matter; the structure does.
| Invalid | Why | Valid |
|---|---|---|
| {'vlan': 10} | Single quotes | {"vlan": 10} |
| [1, 2, 3,] | Trailing comma | [1, 2, 3] |
| {vlan: 10} | Unquoted key | {"vlan": 10} |
| {"up": True} | Booleans are lower case | {"up": true} |
Commands
python3 -m json.tool file.json | Validates and pretty-prints a JSON file. |
show interfaces | json (NX-OS) / RESTCONF GET | Ways devices return JSON. |
Exam traps
- Keys and strings use double quotes; single quotes are invalid.
- No trailing commas and no comments in JSON.
true,falseandnullare lower case and unquoted.- Arrays count from 0.
Check yourself
- Is
{"vlans": [10, 20,]}valid JSON? - No: the trailing comma after 20.
- In the example, what is
interfaces[0].enabled? - true.
- Which structure is ordered: an object or an array?
- An array.
More topics in 6.0 Automation and Programmability
- 6.1 Explain the effect of automation on network operations
- 6.2 Compare device-by-device management with controller-based management
- 6.3 Describe how overlay, underlay and fabric make up a software-defined network
- 6.4 Explain where generative AI, predictive AI and machine learning fit in network operations
- 6.5 Describe REST API characteristics: authentication, CRUD, HTTP verbs, data encoding