6.6 JSON-Encoded Data

Key Takeaways

  • JSON (JavaScript Object Notation) is the most common data format for REST APIs and network automation.
  • JSON uses key-value pairs enclosed in curly braces {} for objects and square brackets [] for arrays.
  • JSON supports strings, numbers, booleans, null, objects, and arrays as data types.
  • JSON is human-readable and machine-parseable, making it ideal for automation.
  • YAML is an alternative to JSON, commonly used in Ansible playbooks — more human-readable but whitespace-sensitive.
Last updated: March 2026

JSON-Encoded Data

JSON (JavaScript Object Notation) is the standard data format for REST APIs and network automation. The CCNA requires you to read and interpret JSON data.

JSON Syntax Rules

  1. Data is in key:value pairs
  2. Data is separated by commas
  3. Curly braces {} hold objects
  4. Square brackets [] hold arrays (ordered lists)
  5. Keys must be strings (in double quotes)
  6. Values can be strings, numbers, booleans, null, objects, or arrays

JSON Data Types

TypeExampleDescription
String"hostname": "SW1"Text in double quotes
Number"vlan_id": 10Integer or decimal (no quotes)
Boolean"enabled": truetrue or false (no quotes)
Null"description": nullEmpty/no value
Object{"name": "SW1"}Nested key-value pairs in {}
Array[10, 20, 30]Ordered list in []

JSON Examples for Networking

Simple Device Object

{
  "hostname": "Core-SW1",
  "management_ip": "10.0.0.1",
  "platform": "Catalyst 9300",
  "software_version": "17.9.4",
  "serial_number": "FCW2145L0KP",
  "uptime_days": 45,
  "reachable": true
}

Array of VLANs

{
  "vlans": [
    {
      "id": 10,
      "name": "SALES",
      "state": "active",
      "ports": ["Gi0/1", "Gi0/2", "Gi0/3"]
    },
    {
      "id": 20,
      "name": "ENGINEERING",
      "state": "active",
      "ports": ["Gi0/4", "Gi0/5", "Gi0/6"]
    },
    {
      "id": 30,
      "name": "MANAGEMENT",
      "state": "active",
      "ports": ["Gi0/7"]
    }
  ]
}

Nested OSPF Configuration

{
  "ospf": {
    "process_id": 1,
    "router_id": "1.1.1.1",
    "areas": [
      {
        "area_id": 0,
        "networks": [
          {
            "network": "10.0.0.0",
            "wildcard": "0.0.0.3"
          },
          {
            "network": "192.168.10.0",
            "wildcard": "0.0.0.255"
          }
        ]
      }
    ],
    "passive_interfaces": ["GigabitEthernet0/1"],
    "reference_bandwidth": 10000,
    "default_information_originate": true
  }
}

Reading JSON — Practice

Given this JSON, answer:

{
  "interfaces": [
    {
      "name": "GigabitEthernet0/0",
      "ip_address": "10.0.0.1",
      "subnet_mask": "255.255.255.252",
      "status": "up",
      "protocol": "up",
      "speed": "1000 Mbps",
      "duplex": "full"
    },
    {
      "name": "GigabitEthernet0/1",
      "ip_address": "192.168.10.1",
      "subnet_mask": "255.255.255.0",
      "status": "up",
      "protocol": "up",
      "speed": "1000 Mbps",
      "duplex": "full"
    }
  ]
}
  • Q: What is the IP address of GigabitEthernet0/1?

  • A: 192.168.10.1

  • Q: How many interfaces are in the array?

  • A: 2 (the array has two objects)

  • Q: What is the subnet mask of the first interface?

  • A: 255.255.255.252

JSON vs. YAML vs. XML

FeatureJSONYAMLXML
FormatKey-value, curly bracesKey-value, indentationTags (like HTML)
ReadabilityGoodBestVerbose
Used byREST APIs, JavaScriptAnsible playbooksLegacy APIs, SOAP
WhitespaceIgnoredSignificant (indentation matters)Ignored
CommentsNot supportedSupported (#)Supported (<!-- -->)

On the Exam: You will likely see a JSON output and be asked to identify specific values. Practice reading nested JSON structures — know how to find values in objects and arrays.

Test Your Knowledge

In JSON, which characters are used to denote an array (ordered list)?

A
B
C
D
Test Your Knowledge

Given this JSON: {"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?

A
B
C
D
Test Your Knowledge

Which data format is most commonly used for REST API responses in network automation?

A
B
C
D