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.
Table of Contents
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
Feature | JSON | YANG |
---|---|---|
Type | Data format | Data modeling language |
Used With | RESTCONF, APIs | NETCONF, RESTCONF |
Human Readable | Yes | Partially |
Language | JavaScript-inspired syntax | YANG-specific |
Function | Represents data (config/operational) | Defines structure and rules for data |
Output Example | {"hostname": "router1"} | leaf hostname { type string; } |
Vendor Support | All modern platforms | Supported by most (Cisco, Juniper) |
Pros and Cons
Pros of JSON | Pros of YANG |
---|---|
Easy to read and parse | Provides a schema for consistency |
Lightweight and fast | Enables model-driven automation |
Ideal for APIs | Works with NETCONF & RESTCONF |
Cons of JSON | Cons of YANG |
---|---|
No schema enforcement by default | Requires learning syntax |
Can become complex at scale | Less readable for beginners |
Essential CLI Commands (JSON/YANG-Related)
Purpose | Command | Description |
---|---|---|
Enable RESTCONF | restconf | Activates RESTCONF on IOS-XE |
Enable secure server | ip http secure-server | Required for REST API over HTTPS |
Check REST status | show platform software restconf statistics | Verifies API service running |
Get supported YANG models | show restconf yang-models | Lists available YANG modules |
View running-config in JSON | API call: GET /restconf/data/native | Returns config in JSON |
Debug API transactions | debug restconf all | Logs JSON/YANG activity |
Log events | `show logging | i restconf` |
Real-World Use Case – Automating Interface Monitoring
Scenario | Detail |
---|---|
Environment | Enterprise with 100+ Cisco routers |
Problem | Manual tracking of interface up/down status |
Solution | Python script using RESTCONF to GET /interfaces in JSON format |
YANG Model Used | ietf-interfaces.yang |
Benefit | Automated 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
- Accept:
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
Problem | Cause | Solution |
---|---|---|
404 Not Found | Wrong endpoint or URL | Verify path and model |
401 Unauthorized | Bad credentials | Check username/password |
Empty JSON | No data in config | Ensure interfaces are configured |
curl/Postman timeout | HTTP server disabled | Use ip http secure-server |
YANG model missing | Platform limitation | Use 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:
Feature | JSON (RESTCONF) | XML (NETCONF) |
---|---|---|
Format | Lightweight, easy to read | Verbose, tag-based |
Used with | RESTCONF, web APIs | NETCONF |
Developer use | Preferred in automation | Common in legacy systems |
Readability | Very human-readable | Requires 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 Suite – https://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:
- Uses the
requests
library to send HTTP requests - Structures the payload in JSON format (following the YANG model)
- 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:
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.
Email: info@networkjourney.com
WhatsApp / Call: +91 97395 21088
Upskill now and future-proof your networking career!