6.6 JSON-Encoded Data
Key Takeaways
- JSON (JavaScript Object Notation) is the dominant data format for REST APIs and network automation.
- Curly braces {} hold objects (key-value pairs); square brackets [] hold arrays (ordered lists).
- JSON values can be strings, numbers, booleans, null, objects, or arrays; keys are always quoted strings.
- Arrays are zero-indexed — the first element is index 0 — which the exam tests with read-a-value questions.
- YAML and XML are alternatives: YAML (Ansible) is whitespace-significant; XML (NETCONF/SOAP) is verbose tag-based.
Why JSON Matters
JSON (JavaScript Object Notation) is the standard payload format for REST APIs and network automation tools. The CCNA does not ask you to write JSON, but it does ask you to read a JSON block and pull out a specific value — and to recognize valid syntax.
Syntax Rules
- Data is written as "key": value pairs.
- Pairs are separated by commas (no trailing comma after the last one).
- Curly braces
{}enclose an object (an unordered set of key-value pairs). - Square brackets
[]enclose an array (an ordered list). - Keys must be strings in double quotes — single quotes are invalid JSON.
- Values may be a string, number, boolean, null, object, or array.
Data Types
| Type | Example | Notes |
|---|---|---|
| String | "hostname": "SW1" | Always double-quoted |
| Number | "vlan_id": 10 | No quotes; integer or decimal |
| Boolean | "enabled": true | true/false, no quotes |
| Null | "description": null | Empty value, no quotes |
| Object | {"name": "SW1"} | Nested key-value set |
| Array | [10, 20, 30] | Ordered list, zero-indexed |
Simple Device Object
{
"hostname": "Core-SW1",
"management_ip": "10.0.0.1",
"platform": "Catalyst 9300",
"software_version": "17.9.4",
"uptime_days": 45,
"reachable": true
}
Here uptime_days is a number (no quotes) and reachable is a boolean — distinguishing those from strings is a common exam point.
Nested Structures and Arrays
Real API output nests objects inside arrays inside objects. Reading it is a navigation drill.
Array of VLAN Objects
{
"vlans": [
{ "id": 10, "name": "SALES", "ports": ["Gi0/1", "Gi0/2"] },
{ "id": 20, "name": "ENGINEERING", "ports": ["Gi0/4", "Gi0/5"] },
{ "id": 30, "name": "MANAGEMENT", "ports": ["Gi0/7"] }
]
}
The vlans array holds 3 objects. To get the name of the second VLAN you read vlans → index 1 (zero-indexed) → name = "ENGINEERING".
Reading Practice
{
"interfaces": [
{ "name": "GigabitEthernet0/0", "ip_address": "10.0.0.1", "status": "up" },
{ "name": "GigabitEthernet0/1", "ip_address": "192.168.10.1", "status": "up" }
]
}
- How many interfaces? 2 (the array has two objects).
- IP of GigabitEthernet0/1?
192.168.10.1— index 1 of the array. - Status of the first interface?
up— index 0.
Drill the zero-indexed rule: index 0 is the first element, index 1 is the second. The exam loves to ask for "the value at index 1" expecting you to skip the first object.
JSON vs. YAML vs. XML
| Feature | JSON | YAML | XML |
|---|---|---|---|
| Structure | Braces/brackets | Indentation | Opening/closing tags |
| Readability | Good | Best | Verbose |
| Used by | REST APIs, RESTCONF | Ansible playbooks | NETCONF, SOAP, legacy |
| Whitespace | Ignored | Significant | Ignored |
| Comments | Not supported | Supported with # | Supported <!-- --> |
Common Traps
- JSON has no comments. If an option claims you can add
# noteinside JSON, it is wrong — that is YAML. - YAML is whitespace-sensitive. A misaligned space breaks an Ansible playbook; JSON does not care about indentation.
- Quotes matter in JSON.
"true"is a string;trueis a boolean. Keys must use double quotes. - Don't confuse the encodings by protocol: RESTCONF can use JSON or XML, NETCONF uses XML only — a fact echoed in the review section.
On the Exam: Expect a JSON block and a "what is the value of X" question. Identify objects
{}vs arrays[], count array elements, and apply zero-indexing to find the right element.
A Step-by-Step Method for Reading JSON
When a JSON block lands on your screen under time pressure, work it like a treasure map rather than reading top to bottom. First, locate the outermost container: a leading { means the whole thing is an object you index by key name, while a leading [ means it is an array you index by position. Second, follow the path the question implies — if it asks for the IP of the third interface, find the interfaces key, drop into its array, and count to position 2 because arrays start at index 0.
Third, confirm the data type of the value you land on, since a question may hinge on whether "10" is a string or 10 is a number, or whether reachable is the boolean true versus the string "true".
A worked walk-through: given {"router": {"id": 5, "acls": [{"name": "GUARD", "rules": 12}, {"name": "GUEST", "rules": 3}]}}, the question "how many rules does the GUEST ACL have?" resolves as router → acls → index 1 (the second object, because GUARD at index 0 comes first) → rules = 3. Notice the value 3 is a number, not a string, so it carries no quotes. This discipline — outermost container, follow the path, check the type — answers virtually every JSON-reading item the CCNA can throw at you.
Validity Checks the Exam Loves
The other JSON skill tested is spotting invalid syntax. Watch for keys written without double quotes, single quotes used anywhere (JSON requires double quotes), a stray trailing comma after the final element, mismatched braces and brackets, or an attempt to add a # or // comment — all of which make the JSON invalid. Recognizing why a snippet would fail to parse is just as fair game as reading a value out of a valid one, and the same brace-versus-bracket and quoting rules drive both kinds of question.
In JSON, which characters denote an array (an ordered list of values)?
Given {"device": {"hostname": "R1", "interfaces": [{"name": "Gi0/0", "ip": "10.0.0.1"}, {"name": "Gi0/1", "ip": "10.0.1.1"}]}}, what is the IP address of Gi0/1?
Which statement about JSON, YAML, and XML is correct?