How to Master JSON for the Cisco DevNet Associate Exam

Learn how JSON powers network automation, APIs, and config management—its benefits, limitations, and real-world use in tools like Ansible and Cisco platforms.


Cisco DevNet Associate course 003 Software Development and Design Compare data Formats JSON

Watch Full Demo on YouTube:

Introduction:

Today, we’re going to explore JSON (JavaScript Object Notation) – the lightweight data format that powers modern network automation, APIs, and configuration management. Whether you’re working with Cisco DNA Center, Ansible playbooks, or RESTCONF interfaces, understanding JSON is essential for today’s network professionals.

We’ll start by examining what makes JSON so valuable in networking environments. You’ll see real-world examples of how JSON structures network device configurations, API responses, and monitoring data in a way that’s both human-readable and machine-friendly. We’ll compare it to alternatives like XML and YAML, highlighting why JSON has become the preferred choice for many automation tasks.

But we won’t stop there – we’ll also take an honest look at JSON’s limitations. Where does it fall short? When might you want to use other formats instead? We’ll discuss the strict syntax rules that can trip you up, the lack of commenting support, and situations where JSON might not be the most efficient choice.

By the end of our discussion, you’ll have a clear understanding of:

  • JSON’s key benefits for network automation and API integration
  • Its major drawbacks and limitations
  • How to decide when to use JSON versus other formats
  • Practical examples from real network engineering scenarios

This balanced perspective will help you work with JSON more effectively in your day-to-day network operations and automation projects. Let’s dive in and unpack what makes JSON so useful – and where you need to be careful with it!

What is JSON?

JSON (JavaScript Object Notation) is like the universal translator for data. It’s a lightweight, text-based format that lets you organize information in a way that’s easy for humans to read and easy for machines to parse. Think of it as a cleaner, simpler alternative to XML—no messy tags, just pure data structure.

  • Born from JavaScript: Created by Douglas Crockford in the early 2000s, it started as a way to handle data in web apps but exploded in popularity because everyone loved how simple it was.
  • File Extensions: JSON files end with .json.
  • Internet’s Favorite Data Format: When servers and web apps talk to each other (like APIs), they often use JSON. Its official internet media type is application/json.

Why Do We Use JSON?

  1. Web Apps & APIs: Ever used a weather app? It probably fetches data like temperature in JSON format.
  2. Config Files: Many tools (like VS Code or npm) use .json files to store settings.
  3. Language Agnostic: Works with Python, Java, C++, and pretty much any modern language.
  4. Network Data Transfer: When you log into a website, your username/password might travel as JSON.

Key Traits of JSON

✅ Human-Readable: Unlike binary formats, you can open a .json file and actually understand it.
✅ Lightweight: No extra fluff—just data. Faster to send over networks than XML.
✅ Structured: Uses key-value pairs (like a dictionary) and arrays (lists).

JSON Example: Network Device Inventory

Imagine you’re documenting routers and switches in your network. Here’s how JSON structures this data cleanly:

{
  "network_devices": [
    {
      "hostname": "core-router-1",
      "ip": "10.0.0.1",
      "vendor": "Cisco",
      "model": "ASR-1001-X",
      "interfaces": [
        {
          "name": "GigabitEthernet0/0",
          "ip_address": "192.168.1.1",
          "subnet_mask": "255.255.255.0",
          "status": "up"
        },
        {
          "name": "GigabitEthernet0/1",
          "ip_address": "10.1.1.1",
          "subnet_mask": "255.255.255.252",
          "status": "down"
        }
      ]
    },
    {
      "hostname": "access-switch-1",
      "ip": "10.0.0.2",
      "vendor": "Juniper",
      "model": "EX4300",
      "vlans": [10, 20, 30]
    }
  ]
}

Why This Matters for Networking

  1. API Automation
    Tools like Ansible or Python scripts use JSON to push configs to devices via APIs (e.g., Cisco DNA Center, Meraki Dashboard).
  2. Health Monitoring
    Network management systems return device stats (CPU, uptime) in JSON:
{
  "device": "core-router-1",
  "cpu_usage": 45%,
  "memory_free": "2GB",
  "last_reboot": "2023-10-15T08:00:00Z"
}
  1. SDN Controllers
    Software-Defined Networking (SDN) platforms like OpenDaylight export topology data as JSON.

JSON Syntax: The Rules of the Road

Alright, let’s talk about JSON syntax—the grammar rules that keep your data from turning into gibberish. Think of it like configuring a router: miss a semicolon or typo an IP, and nothing works. JSON has the same “strict but simple” vibe. Here’s how to get it right:

1. The Basic Building Blocks

JSON is made of just two structures:

  • Objects: { } → Hold key-value pairs (like a router’s interface config).
  • Arrays: [ ] → Hold lists of values (like a list of VLANs).

Example (Network Device):

{
  "device": "core-switch-1",
  "ip": "10.0.0.1",
  "is_up": true,
  "vlans": [10, 20, 30],
  "interfaces": [
    { "name": "Gi1/0/1", "status": "up" },
    { "name": "Gi1/0/2", "status": "down" }
  ]
}
  • Keys (“device”, “ip”) are always in double quotes.
  • Values can be:
    • Strings (“core-switch-1”)
    • Numbers (10)
    • Booleans (true/false)
    • Arrays ([10, 20, 30])
    • Nested objects ({ “name”: “Gi1/0/1” })

2. Critical Syntax Rules

✅ Double quotes only: “ip” works, ‘ip’ fails.
✅ Commas separate items: Forget one? Syntax error.
✅ No trailing commas: This breaks JSON:

{
  "vlan": 10,  // ✅
  "name": "mgmt",  // ❌ (trailing comma)
}

3. Real-World Network Examples

a. BGP Neighbor Configuration (Cisco-style)

{
  "bgp_neighbors": [
    {
      "ip": "192.168.1.2",
      "remote_as": 65002,
      "description": "Peering with ISP-A"
    },
    {
      "ip": "192.168.2.2",
      "remote_as": 65003,
      "description": "Peering with ISP-B"
    }
  ]
}

b. Interface Status (API Response)

{
  "interface": "GigabitEthernet0/0",
  "ip_address": "10.1.1.1/24",
  "oper_status": "up",
  "in_errors": 0,
  "out_errors": 0
}

4. Common Pitfalls (And How to Avoid Them)

🚨 Mistake: Missing quotes around keys.

{ device: "core-router-1" }  // ❌ Fails!
{ "device": "core-router-1" }  // ✅ Works

🚨 Mistake: Using undefined or comments.

{
  "hostname": "switch-1",
  // "location": "Data Center A"  // ❌ Comments aren’t allowed!
  "status": undefined  // ❌ Use `null` instead
}

🚨 Mistake: Single quotes (common in Python, but JSON hates them).

{ 'hostname': 'router-1' }  // ❌
{ "hostname": "router-1" }  // ✅

5. Tools to Validate JSON

  • VS Code: Highlights syntax errors in .json files.
  • Online ValidatorsJSONLint
  • Python:
import json
try:
    json.loads('{"device": "router-1"}')  # Valid
except json.JSONDecodeError as e:
    print("Invalid JSON:", e)

Why This Matters

  • APIs: Cisco DNA Center, Meraki, and other network tools use JSON for config templates and health checks.
  • Automation: Ansible/scripts read/write JSON to manage devices at scale.
  • Debugging: Ever seen a API error? 90% of the time, it’s a JSON syntax typo.

Try It Yourself

  1. Open notepad, paste this, save as device.json:
{
  "hostname": "your-router",
  "interfaces": [
    { "name": "Gi0/0", "ip": "192.168.1.1" }
  ]
}
  1. Validate it at JSONLint (https://jsonlint.com/).

Pro Tip: In Python, json.dumps() converts objects to JSON (great for scripts!).

JSON Data Types: What Goes Where?

JSON isn’t just about curly braces and commas—it’s picky about what types of data you can put in it. Think of it like configuring a router: you can’t type shutdown when the CLI expects an IP address. JSON has similar rules. Let’s break them down with real networking examples.

1. The 6 JSON Data Types

TypeExample (Network Context)Why It Matters
String“hostname”: “core-switch-1”Hostnames, interface names, descriptions.
Number“mtu”: 1500MTU sizes, VLAN IDs, AS numbers.
Boolean“is_up”: trueInterface status (up/down).
Array“vlans”: [10, 20, 30]Lists of VLANs, IP prefixes.
Object{“interface”: {“name”: “Gi0/0”}}Nested configs (e.g., BGP neighbors).
null“error_count”: nullPlaceholder for empty values.

2. Networking Examples for Each Type

a. Strings (Text)

Used for anything alphanumeric:

{
  "hostname": "edge-router-nyc",
  "model": "Cisco ISR-4431",
  "description": "Primary WAN router"
}

⚠️ Gotcha: “10” (string) vs 10 (number). APIs often fail if you mix these!

b. Numbers (No Quotes!)

Used for numeric values:

{
  "as_number": 65001,       // BGP ASN
  "vlan_id": 100,           // VLAN
  "bandwidth_mbps": 1000    // Interface speed
}

c. Booleans (true/false)

For binary states:

{
  "ospf_enabled": true,
  "port_security": false
}

d. Arrays (Lists)

Groups of similar items:

{
  "acl_rules": ["permit tcp any any", "deny ip any any"],
  "ip_addresses": ["10.0.0.1", "10.0.0.2"]
}

e. Objects (Nested Configs)

For hierarchical data (e.g., BGP peers):

{
  "bgp_peer": {
    "ip": "192.168.1.2",
    "remote_as": 65002,
    "password": "Cisco123!"
  }
}

f. null (Explicit Empty Values)

When data is missing or reset:

{
  "last_error": null,  // No errors logged
  "backup_ip": null    // Not configured
}

3. Network-Specific Gotchas

🚨 Mistake: Using numbers for strings (or vice versa).

{
  "vlan": "100"  // ❌ API expects a number (100), not a string ("100")
}

🚨 Mistake: Forgetting null vs omitting keys.

{ "ospf_area": null }  // "OSPF area is explicitly empty"  
{}                     // "OSPF area is unknown"  

🚨 Mistake: Booleans as strings.

{ "is_stp_enabled": "true" }  // ❌ Should be `true` (no quotes!)

4. Why Data Types Matter in Networking

  • APIs: Cisco DNA Center/Meraki APIs fail if you send a string “65001” instead of number 65001 for an ASN.
  • Automation: Ansible/YAML often converts to JSON—knowing types prevents cryptic errors.
  • Validation: JSON schemas (like Cisco’s YANG models) enforce types strictly.

Real-World Example:
This Cisco DNAC API snippet requires numbers for vlanId and booleans for voiceVlan:

{
  "vlanId": 100,     // Number
  "voiceVlan": false // Boolean
}

5. Tools to Check Types

  • Python:
import json
config = json.loads('{"vlan": 100}')
print(type(config["vlan"]))  # Output: <class 'int'>
  • VS Code: Hovers show inferred types in .json files.
  • jq (CLI):
echo '{"hostname": "sw1"}' | jq 'type'
# Output: "object"

Benefits and Drawbacks of JSON:

JSON (JavaScript Object Notation) has become the lingua franca of data exchange in modern IT, especially in networking and automation. But like any tool, it has strengths and weaknesses. Let’s break them down with real-world networking examples.

Benefits of JSON:

1. Human-Readable and Intuitive

JSON’s key-value pair structure is easy to read and write, even for non-programmers.

Example (vs. XML):

{
  "router": {
    "hostname": "R1",
    "interfaces": [
      { "name": "Gi0/0", "ip": "10.0.0.1" }
    ]
  }
}

vs. XML:

<router>
  <hostname>R1</hostname>
  <interfaces>
    <interface>
      <name>Gi0/0</name>
      <ip>10.0.0.1</ip>
    </interface>
  </interfaces>
</router>

Why it matters?

  • Easier to debug config files.
  • Faster to modify manually (e.g., tweaking an Ansible playbook).

2. Lightweight and Fast to Parse

JSON has no extra markup (unlike XML’s closing tags), making it:

  • Smaller in file size → Faster to transmit over networks.
  • Quicker for machines to parse → Better performance in APIs.

Example (Cisco DNA Center API response):

{
  "device": "switch-1",
  "uptime": "5 days",
  "interfaces": ["Gi1/0/1", "Gi1/0/2"]
}

Why it matters?

  • Critical for high-frequency API calls (e.g., monitoring 1000 devices).

3. Language-Agnostic

JSON works with almost every programming language:

  • Python: json.loads() / json.dumps()
  • JavaScript: JSON.parse()
  • Go, Java, C#, etc.: Built-in support.

Example (Python + JSON for network automation):

import json
config = json.loads('{"vlan": 100, "name": "mgmt"}')
print(config["vlan"])  # Output: 100

Why it matters?

  • Write a script in Python, and it’ll work with the same JSON data in JavaScript or Go.

4. Perfect for APIs (REST, RESTCONF, etc.)

Most network automation tools (Cisco DNA Center, Ansible, Terraform) use JSON for:

  • Config templates
  • Device status monitoring
  • Bulk updates

Example (Cisco IOS-XE RESTCONF):

command: curl -X GET https://router/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces -H “Accept: application/json”

Response:

{
  "interface": [
    {
      "name": "GigabitEthernet1",
      "ipv4": "10.0.0.1",
      "status": "up"
    }
  ]
}

Why it matters?

  • Standardized way to interact with network devices.

5. Supports Nested Data (Trees, Lists, etc.)

JSON handles complex structures easily:

  • Arrays ([]) → Lists of VLANs, ACL rules.
  • Objects ({}) → Nested device configs.

Example (BGP config in JSON):

{
  "bgp": {
    "asn": 65001,
    "neighbors": [
      { "ip": "192.168.1.2", "remote_as": 65002 },
      { "ip": "192.168.2.2", "remote_as": 65003 }
    ]
  }
}

Why it matters?

  • Ideal for network device configurations (e.g., pushing BGP peers via Ansible).

Drawbacks of JSON:

1. No Comments (Unlike YAML/XML)

JSON doesn’t allow comments, making it harder to document:

{
  "vlan": 100,
  // "description": "Mgmt VLAN"  ❌ Invalid JSON!
}

Workaround: Use a “_comment” key (but it’s messy).

Why it hurts?

  • Harder to maintain large config files.

2. Strict Syntax (Easy to Break)

  • Missing comma? { “vlan”: 100 “name”: “mgmt” } → Fails.
  • Trailing comma? { “vlan”: 100, } → Fails.

Why it hurts?

  • Manual edits often lead to API errors.

3. Verbose for Some Use Cases

While better than XML, JSON is still heavier than YAML for configs:

JSON:

{
  "vlans": [
    { "id": 10, "name": "mgmt" },
    { "id": 20, "name": "voice" }
  ]
}

Equivalent YAML:

vlans:
  - id: 10
    name: mgmt
  - id: 20
    name: voice

Why it hurts?

  • YAML is better for human-written configs (Ansible playbooks).

4. No Advanced Data Types

JSON lacks support for:

  • Dates → Must use strings (“2023-10-20”).
  • Binary data → Must be Base64-encoded.

Example (Problem with dates):

{
  "last_backup": "2023-10-20T12:00:00Z"  // Not a real date type
}

Why it hurts?

  • Requires extra parsing in code.

5. Poor for Large Datasets

JSON isn’t ideal for:

  • High-frequency telemetry (e.g., streaming interface stats).
  • Large binary files (e.g., firmware images).

Alternatives:

  • Protocol Buffers (Google’s binary format).
  • MessagePack (Binary JSON-like format).

💡 When to Use JSON in Networking?

Use JSON WhenAvoid JSON When
APIs (REST, RESTCONF)Large binary data (e.g., PCAPs)
Ansible/Terraform configsHuman-edited configs (YAML better)
Device status monitoringHigh-speed telemetry (use Protobuf)
Nested data (BGP configs)Adding code comments (use YAML)

References:

DevNet Associate – Cisco

Cisco Certified DevNet Expert (v1.0) Equipment and Software List

DevNet Associate Exam Topics


Discover more from IEE

Subscribe to get the latest posts sent to your email.


Discover more from IEE

Subscribe now to keep reading and get access to the full archive.

Continue reading