Introduction to JSON & YANG – The Foundation of Network Automation [CCNP Enterprise]

Introduction to JSON & YANG – The Foundation of Network Automation [CCNP Enterprise]

You’ve probably heard the terms JSON and YANG thrown around in the world of network automation, but they might still feel like mysterious tech-jargon to some. Trust me—I was there too. In this post, I’ll walk you through what JSON and YANG really mean for network engineers and why they’re essential as we step into the era of intent-based networking and APIs.

Think of JSON as the language your devices use to talk data, and YANG as the dictionary that defines the grammar. Whether you’re working with REST APIs, NETCONF, or modern Cisco controllers, JSON and YANG are quietly doing the heavy lifting behind the scenes. Let’s simplify these concepts, see them in action with an EVE-NG lab, and prepare you for the real-world DevNet and CCNP Enterprise landscape.


Theory in Brief – What Are JSON and YANG?

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format used to represent structured data. It’s readable, compact, and widely used in network APIs like RESTCONF. Cisco devices supporting REST APIs typically return responses in JSON format when queried.

A simple JSON object looks like this:

{
"interface": {
"name": "GigabitEthernet1",
"enabled": true,
"ip": "192.168.1.1"
}
}

This format is easy to read for both machines and humans, making it the preferred choice for modern automation scripts.


What is YANG?

YANG (Yet Another Next Generation) is a data modeling language used to define the structure of configuration and operational data on a network device. It’s like a blueprint that tells APIs and applications what data is available and how it should look.

Think of YANG as the schema or model for devices that use NETCONF or RESTCONF protocols. It ensures consistency, validation, and structure in network data.

Example YANG snippet:

leaf interface-name {
type string;
description "Name of the interface";
}

JSON & YANG Together

When you query a Cisco router via RESTCONF, the response you get is in JSON. But that JSON structure is defined and validated using a YANG model behind the scenes. It’s a powerful duo: JSON transports the data, and YANG defines what’s allowed in that data.


Comparision– JSON vs YANG

FeatureJSONYANG
TypeData formatData modeling language
Used WithRESTCONF, APIsNETCONF, RESTCONF
Human ReadableYesPartially
LanguageJavaScript-inspired syntaxYANG-specific
FunctionRepresents data (config/operational)Defines structure and rules for data
Output Example{"hostname": "router1"}leaf hostname { type string; }
Vendor SupportAll modern platformsSupported by most (Cisco, Juniper)

Pros and Cons

Pros of JSONPros of YANG
Easy to read and parseProvides a schema for consistency
Lightweight and fastEnables model-driven automation
Ideal for APIsWorks with NETCONF & RESTCONF
Cons of JSONCons of YANG
No schema enforcement by defaultRequires learning syntax
Can become complex at scaleLess readable for beginners

Essential CLI Commands (JSON/YANG-Related)

PurposeCommandDescription
Enable RESTCONFrestconfActivates RESTCONF on IOS-XE
Enable secure serverip http secure-serverRequired for REST API over HTTPS
Check REST statusshow platform software restconf statisticsVerifies API service running
Get supported YANG modelsshow restconf yang-modelsLists available YANG modules
View running-config in JSONAPI call: GET /restconf/data/nativeReturns config in JSON
Debug API transactionsdebug restconf allLogs JSON/YANG activity
Log events`show loggingi restconf`

Real-World Use Case – Automating Interface Monitoring

ScenarioDetail
EnvironmentEnterprise with 100+ Cisco routers
ProblemManual tracking of interface up/down status
SolutionPython script using RESTCONF to GET /interfaces in JSON format
YANG Model Usedietf-interfaces.yang
BenefitAutomated polling, easy integration with Grafana/Slack alerts

EVE-NG Lab – Exploring JSON & YANG on Cisco IOS-XE

Objective

  • Enable RESTCONF
  • Query interfaces using JSON
  • Validate data against YANG model

Lab Topology


Step-by-Step Config on Cisco Router

1. Enable RESTCONF & Secure Server

conf t
ip http secure-server
restconf
username admin privilege 15 secret admin123

2. Verify Available YANG Models

show restconf yang-models

Sample Output:

Module Name: ietf-interfaces
Module Name: Cisco-IOS-XE-native

3. Query Using Postman or curl

GET Request to fetch interface data:

  • URL: https://<router-ip>/restconf/data/ietf-interfaces:interfaces
  • Auth: Basic (admin/admin123)
  • Headers:
    • Accept: application/yang-data+json
    • Content-Type: application/yang-data+json

4. Expected JSON Output

{
"ietf-interfaces:interfaces": {
"interface": [
{
"name": "GigabitEthernet1",
"enabled": true,
"ipv4": {
"address": [
{
"ip": "10.0.0.1",
"netmask": "255.255.255.0"
}
]
}
}
]
}
}

Troubleshooting Tips

ProblemCauseSolution
404 Not FoundWrong endpoint or URLVerify path and model
401 UnauthorizedBad credentialsCheck username/password
Empty JSONNo data in configEnsure interfaces are configured
curl/Postman timeoutHTTP server disabledUse ip http secure-server
YANG model missingPlatform limitationUse supported firmware version

FAQs – JSON & YANG Simplified

1. What is JSON and why is it important in network automation?

Answer:
JSON (JavaScript Object Notation) is a lightweight, human-readable data format used to represent structured data. It’s important in network automation because:

  • It’s easy for both humans and machines to read and write.
  • It’s widely used in REST APIs for sending and receiving data to/from network devices.
  • Tools like Postman, Python scripts, and automation platforms (e.g., Ansible, Cisco DNA Center) rely heavily on JSON for communication.
    In short, JSON makes automation cleaner, faster, and more developer-friendly.

2. What is YANG and how does it relate to network configuration?

Answer:
YANG (Yet Another Next Generation) is a data modeling language used to describe the configuration and operational state of network devices. It is used with protocols like NETCONF and RESTCONF.
YANG models define the structure, hierarchy, and rules for device configuration — like defining what an “interface” object should look like and what parameters it should include (e.g., name, IP address, status).
Think of YANG as the blueprint, and JSON/XML as the actual data being exchanged.


3. How are JSON and YANG connected in Cisco network automation?

Answer:
Cisco platforms like IOS XE and NX-OS use YANG models to define what can be configured or queried. When a RESTCONF API is used:

  • The YANG model determines the data structure.
  • The JSON payload contains the actual data being configured or retrieved.
    For example, to configure an interface via RESTCONF, the structure of the JSON body must align with the interface’s YANG model.

4. What is the difference between JSON and XML in RESTCONF and NETCONF?

Answer:

FeatureJSON (RESTCONF)XML (NETCONF)
FormatLightweight, easy to readVerbose, tag-based
Used withRESTCONF, web APIsNETCONF
Developer usePreferred in automationCommon in legacy systems
ReadabilityVery human-readableRequires more parsing

Cisco RESTCONF typically uses JSON, while NETCONF relies on XML. Both represent data structured by YANG models.


5. What are some common YANG models used in Cisco networks?

Answer:
Cisco provides many native and standard YANG models, including:

  • ietf-interfaces: Standard model for configuring interfaces
  • Cisco-IOS-XE-native: Cisco-specific features like VLANs, routing, etc.
  • ietf-routing: Standard routing configuration
  • openconfig-interfaces: Vendor-neutral model used in multivendor environments
    You can view supported models using:
GET https://<device-ip>/restconf/data/ietf-yang-library:modules-state

6. Where can I find and browse YANG models?

Answer:
You can browse Cisco YANG models from:

  • Cisco DevNet YANG Suitehttps://yangsuite.cisco.com/
  • GitHub (Cisco & OpenConfig repos)
  • YANG Explorer Tool – For visualizing and interacting with YANG models
    These tools help you understand the hierarchy and structure needed for automation tasks.

7. What are some use cases of JSON/YANG in real-world network automation?

Answer:
Real-world use cases include:

  • Automating interface configuration across routers/switches
  • Retrieving operational data (CPU, memory, interface status)
  • Pushing bulk changes like VLAN provisioning or ACLs
  • SDN Integration with platforms like Cisco DNA Center
    They are used in both brownfield (existing) and greenfield (new) deployments to reduce CLI usage and human error.

8. How does Python interact with JSON and YANG models in automation scripts?

Answer:
Python is the most popular language for network automation and works seamlessly with JSON. A typical script:

  1. Uses the requests library to send HTTP requests
  2. Structures the payload in JSON format (following the YANG model)
  3. Sends it to the device’s RESTCONF API
    Example:
import requests
headers = {'Content-Type': 'application/yang-data+json'}
payload = {"ietf-interfaces:interface": {"name": "Gig1", "type": "iana-if-type:ethernetCsmacd"}}
response = requests.put(url, headers=headers, json=payload, auth=('admin', 'cisco'))

9. Do I need to learn YANG syntax as a network engineer?

Answer:
Not in depth—but understanding the basics of YANG structure (containers, lists, leaves) is essential if you’re doing API-based automation.
You don’t need to write YANG models but should know how to:

  • Interpret YANG to build correct JSON/XML payloads
  • Use tools like YANG Suite or Postman to interact with models
    This bridges the gap between traditional CLI and modern automation.

10. What tools can help me test JSON/YANG-based automation with Cisco devices?

Answer:

  • Cisco YANG Suite – For testing and validating YANG models and RESTCONF/NETCONF calls
  • Postman – For building and sending RESTCONF API calls with JSON
  • Python Scripts (with Requests/XML/JSON libraries) – For automation at scale
  • EVE-NG or Cisco DevNet Sandbox – For labbing real scenarios
    These tools allow you to test configurations, retrieve operational data, and debug payload structures.

YouTube Video Link

Watch the Complete CCNP Enterprise: Introduction to JSON & YANG – The Foundation of Network Automation Lab Demo & Explanation on our channel:

Class 1 CCNP Enterprise Course and Lab Introduction | FULL COURSE 120+ HRS | Trained by Sagar Dhawan
Class 2 CCNP Enterprise: Packet Flow in Switch vs Router, Discussion on Control, Data and Management
Class 3 Discussion on Various Network Device Components
Class 4 Traditional Network Topology vs SD Access Simplified

Final Note

Understanding how to differentiate and implementIntroduction to JSON & YANG – The Foundation of Network Automation is critical for anyone pursuing CCNP Enterprise (ENCOR) certification or working in enterprise network roles. Use this guide in your practice labs, real-world projects, and interviews to show a solid grasp of architectural planning and CLI-level configuration skills.

If you found this article helpful and want to take your skills to the next level, I invite you to join my Instructor-Led Weekend Batch for:

CCNP Enterprise to CCIE Enterprise – Covering ENCOR, ENARSI, SD-WAN, and more!

Get hands-on labs, real-world projects, and industry-grade training that strengthens your Routing & Switching foundations while preparing you for advanced certifications and job roles.

Emailinfo@networkjourney.com
WhatsApp / Call: +91 97395 21088

Upskill now and future-proof your networking career!