Study guide
14.2 JSON Data Encoding: Syntax, Formatting Rules, and Python Serialization
Cisco ENCOR 350-401 CCNP Enterprise Core
Track your progress as you read
Finished sections get a check mark.
1 Introduction & Exam Overview
0.1 Cisco 350-401 ENCOR Exam Logistics, Blueprint Structure, and Certification Paths 0.2 Preparation Strategy, Lab Environment Setup, and Practical Test Pacing
2 Enterprise Campus Architecture and High Availability
1.1 Enterprise Network Design: Two-Tier, Three-Tier, Fabric, and Cloud Architectures 1.2 High Availability Architecture: Device Redundancy, FHRPs, and Stateful Switchover (SSO) 1.3 Quality of Service (QoS) Architecture, Classification, Queuing, and Configuration Interpretation
3 Cisco Software-Defined Architecture: SD-WAN and SD-Access
2.1 Cisco Catalyst SD-WAN: Control, Management, and Data Planes 2.2 Cisco SD-Access Architecture: Control Plane, Data Plane, and Fabric Node Roles 2.3 SD-Access Campus Interoperability: Integrating Traditional Networks with Fabric
4 Device and Network Virtualization Technologies
3.1 Device Virtualization: Type 1/2 Hypervisors, Virtual Machines, and Virtual Switching 3.2 Data Path Virtualization: VRF-Lite, GRE Tunneling, and IPsec VPN Fundamentals 3.3 Network Virtualization Overlays: LISP and VXLAN Encapsulation Mechanics
5 Layer 2 Infrastructure: Trunking, EtherChannel, and Spanning Tree
4.1 802.1Q Trunking, Native VLAN, and Dynamic Trunking Protocol Troubleshooting 4.2 EtherChannel Bundling: Static, LACP, and PAgP Implementation and Verification 4.3 Spanning Tree Architecture: RSTP, MST, and STP Protection Mechanisms
6 Layer 3 Routing: OSPF Multi-Area and Protocol Comparison
5.1 Enterprise Routing Principles: Distance Vector vs. Link-State, EIGRP, and OSPF 5.2 OSPFv2 and OSPFv3 Multi-Area Architecture: LSAs, Area Types, and Summarization 5.3 Policy-Based Routing (PBR) Architecture, Configuration, and Route-Maps
7 Exterior Routing: BGP Peering and Path Selection
6.1 External BGP (eBGP) Peering, States, Neighbor Adjacencies, and Timers 6.2 BGP Path Attributes and the Step-by-Step Best Path Selection Algorithm
8 IP Services and First-Hop Redundancy
7.1 Time Synchronization: Network Time Protocol (NTP) and Precision Time Protocol (PTP) 7.2 Network Address Translation: Static NAT, Dynamic NAT, and PAT/Overload 7.3 First Hop Redundancy Protocols: HSRP and VRRP Implementation and Failover
9 IP Multicast Architecture and Protocols
8.1 Multicast Addressing, IGMPv2/v3 Host Membership, and the RPF Check 8.2 Protocol Independent Multicast Sparse Mode (PIM-SM) and Rendezvous Point Discovery 8.3 Anycast RP with MSDP, Source-Specific Multicast (SSM), and Bidirectional PIM
10 Network Diagnostics, Monitoring, and Telemetry
9.1 Network Diagnostic Tools: Conditional Debugging, Traceroute, SNMPv3, and Syslog Logging 9.2 Flexible NetFlow (FNF) Architecture: Flow Records, Exporters, and Monitors 9.3 Switched Port Analyzer: Local SPAN, Remote SPAN (RSPAN), and Encapsulated RSPAN (ERSPAN)
11 Performance Monitoring and Model-Driven Assurance
10.1 IP Service Level Agreements (IP SLA) Probes, Responder, and Route Tracking 10.2 Cisco Catalyst Center: Assurance Dashboards, AI Analytics, and Machine Reasoning Workflows 10.3 Model-Driven Telemetry and Programmable Interfaces: NETCONF and RESTCONF Verification
12 Device Access Control and AAA Architecture
11.1 Device Line Protection: Console, Aux, VTY, Local Authentication, and Privilege Levels 11.2 AAA Architecture: Comparing RADIUS vs. TACACS+ and Method List Configuration
13 Infrastructure Security: ACLs, CoPP, and API Security
12.1 IPv4 and IPv6 Access Control Lists (ACLs): Standard, Extended, and Named Rules 12.2 Control Plane Policing (CoPP): Protecting the Route Processor with MQC 12.3 REST API Security: Token Authentication, TLS Transport, and Rate Limiting
14 Enterprise Network Security Design: ISE, TrustSec, and MACsec
13.1 Endpoint Security Architecture: 802.1X, Cisco ISE Posture, and Profiling 13.2 Next-Generation Firewalls (FTD) and Enterprise Threat Defense Design 13.3 Cisco TrustSec (Security Group Tags) and MACsec (802.1AE) Layer 2 Encryption
15 Network Automation Fundamentals: Python, JSON, and YANG
14.1 Python Fundamentals for Network Engineers: Data Types, Control Flow, and Libraries 14.2 JSON Data Encoding: Syntax, Formatting Rules, and Python Serialization 14.3 YANG Data Modeling: Modules, Tree Structures, and Data Representation
16 Controller REST APIs and RESTCONF Implementation
15.1 Cisco Catalyst Center Intent APIs and Authentication Workflows 15.2 Cisco Catalyst SD-WAN Manager (vManage) REST APIs and Device Interaction 15.3 RESTCONF Protocol Operations: HTTP Verbs, Datastores, and Response Codes
17 Event-Driven Automation and Infrastructure Orchestration
16.1 Cisco Embedded Event Manager (EEM) Applet Architecture and Event Detectors 16.2 Configuration Management: Comparing Ansible, Puppet, Chef, and SaltStack 16.3 Infrastructure as Code (IaC) Principles with Terraform in Enterprise Networks
14.2 JSON Data Encoding: Syntax, Formatting Rules, and Python Serialization
Key Takeaways Explain This Topic AI
JavaScript Object Notation (JSON, RFC 8259) is a lightweight, human-readable, language-agnostic data interchange format and the dominant encoding for modern REST APIs and SDN controllers.
JSON syntax strictly requires that all object keys be double-quoted strings, supporting six value types: string, number, object, array, boolean (lowercase true/false), and null.
Common syntax violations that cause parser failures include single-quoted keys, trailing commas after the final element in arrays or objects, and unescaped control characters.
JSON trades schema enforcement and namespaces (features of XML) for compactness and simplicity, while YAML provides human-oriented whitespace-delimited formatting used in tools like Ansible.
The Python json library provides json.loads() and json.dumps() for in-memory string serialization, and json.load() and json.dump() for reading and writing directly to disk file streams.
Last updated: October 2026
JSON Data Encoding: Syntax, Formatting Rules, and Python Serialization
In modern network programmability, data encoding formats dictate how configuration parameters, telemetry metrics, and controller states are serialized into byte streams for transmission across the network. Historically, network management relied on unstructured, vendor-specific CLI text. When engineers attempted to automate device management through Telnet or SSH screen-scraping, minor firmware updates that altered prompt formatting, column spacing, or status wording frequently broke automation scripts. To establish reliable programmatic interactions, modern controllers such as Cisco Catalyst Center and Cisco Catalyst SD-WAN Manager communicate via RESTful APIs using structured, machine-parseable data formats. JavaScript Object Notation (JSON) , standardized under RFC 8259 , has become the standard encoding format for web APIs and SDN architectures. +-------------------------------------------------------------------------+
- | JSON Data Serialization Pipeline |
- +-------------------------------------------------------------------------+
- [ Cisco Catalyst Center ] [ Network Engineer Script ]
- | |
- | 1. HTTPS GET /dna/intent/api/v1/network-device
- | <--------------------------------------------|
- | |
- | 2. HTTP 200 OK + JSON Payload (Byte Stream) |
- | -------------------------------------------->|
- | |
- +----------------------------+
- | Python In-Memory Parsing |
- | response.json() or |
- | json.loads(response.text) |
- +----------------------------+
- |
- +----------------------------+
- | Deserialized Python Types: |
- | JSON Object -> dict |
- | JSON Array -> list |
- | JSON Bool -> True/False |
- | JSON Null -> None |
- +----------------------------+
- |
- +----------------------------+
- | Serialization to Disk/API: |
- | json.dumps(obj, indent=4) |
- | json.dump(obj, file_obj) |
- +----------------------------+
- JSON Syntax Rules and Structural Constraints
JSON is built upon two universal structural paradigms: a collection of name/value pairs (an object ) and an ordered list of values (an array ). While JSON originated in the JavaScript language, it is completely language-independent and follows strict syntax rules:
1. Key-Value Pairs and Double Quotes
An object begins with an opening curly brace { and ends with a closing curly brace } . Inside an object, each entry is expressed as a key-value pair separated by a colon ( : ). Pairs are separated from each other by commas ( , ). A critical rule of RFC 8259 is that all keys must be strings enclosed in standard double quotation marks ( "key" ) . Using single quotation marks ( 'key' ) or unquoted strings is syntactically invalid and causes JSON parsers to abort with syntax errors.
2. Valid Value Data Types
A JSON value must strictly belong to one of six data types:
String: A sequence of zero or more Unicode characters wrapped in double quotes ( "GigabitEthernet0/0/1" ). Special characters must be escaped with a backslash, such as \" for quotes, \\ for backslashes, and \n for newlines.
Number: Integer or floating-point numeric representations ( 100 , 4094 , 99.95 ). Scientific exponential notation is permitted ( 1.5e3 ), but hexadecimal representations (e.g., 0x1A ), octal values, and special IEEE values such as NaN or Infinity are prohibited.
Object: A nested, unordered collection of zero or more key-value pairs enclosed in {} .
Array: An ordered sequence of zero or more values enclosed in square brackets [] and separated by commas. Arrays can hold heterogeneous data types, although in networking schemas they typically contain lists of uniform objects (such as a list of interface dictionaries).
Boolean: Literal values true or false . Unlike Python, which capitalizes booleans ( True , False ), JSON booleans must be strictly lowercase .
Null: The literal keyword null (strictly lowercase), representing an empty, missing, or unassigned value. When deserialized into Python, null maps to None .
3. Syntax Validation Checklist and Common Pitfalls
Network engineers authoring or parsing JSON frequently encounter syntax errors. The following rules represent the most common points of failure:
No Trailing Commas: A trailing comma after the final key-value pair in an object (e.g., {"host": "rtr1", "vlan": 10,} ) or after the last element in an array (e.g., ["Gi0/1", "Gi0/2",] ) is strictly illegal in RFC 8259. Python dictionaries permit trailing commas, but JSON parsers will fail.
Matching Delimiters: Every opening brace { must have a matching closing brace } , and every opening bracket [ must match a closing bracket ] .
No Inline Comments: JSON does not support comments. Inserting // or /* ... */ comments into a JSON file breaks syntax validation.
Comparing Data Encoding Formats: JSON vs. XML vs. YAML
Enterprise network automation utilizes three prominent data encoding formats, each developed with distinct architectural design objectives: Data Format Architectural Comparison:
- +---------------+---------------------------------------------------------+
- | Format | Syntax Structure & Primary Use Case |
- +---------------+---------------------------------------------------------+
- | JSON | Double-quoted keys, curly braces/brackets. Lightweight, |
- | (RFC 8259) | low-overhead payload format for REST APIs & controllers |
- +---------------+---------------------------------------------------------+
- | XML | Opening/closing tags, schema validation (XSD), |
- | (W3C Standard)| namespaces. Standard payload format for NETCONF |
- +---------------+---------------------------------------------------------+
- | YAML | Indentation-based, human-friendly, supports comments. |
- | (YAML 1.2) | Preferred format for Ansible playbooks & IaC configs |
- +---------------+---------------------------------------------------------+
- JSON (RFC 8259)
JSON balances machine parseability with human readability. Because it avoids the verbose closing tags of XML and the whitespace sensitivity of YAML, JSON provides an optimal, lightweight payload for high-frequency REST API calls between network controllers and management scripts.
XML (Extensible Markup Language)
Standardized by the World Wide Web Consortium (W3C), XML represents data hierarchically using explicit start tags <interface> and end tags </interface> . XML natively supports attributes within tags, XML Namespaces ( xmlns ) for resolving naming collisions across multi-vendor definitions, and formal XML Schema Definitions (XSD) for rigorous structural validation. XML is the mandatory encoding format for NETCONF (RFC 6241), but its verbosity produces higher network bandwidth overhead than JSON.
YAML (YAML Ain't Markup Language)
YAML is a human-centric data serialization language that relies on indentation and whitespace rather than delimiters like curly braces or tags. YAML supports native inline comments ( # ), multiline string folding, and variable anchoring. It is widely used for configuration management files, including Ansible playbooks, Docker Compose manifests, and GitLab CI/CD pipelines. However, its strict sensitivity to whitespace indentation can introduce parsing ambiguities.
Data Encoding Formats Comparison Matrix
Attribute JSON (RFC 8259) XML (W3C Standard) YAML (Version 1.2)
Syntactic Delimiters Braces {} , brackets [] , quotes "" Start <tag> and end </tag> elements Whitespace indentation, colons, dashes -
- Structural Verbosity Low to moderate High (repeated closing tags) Minimal (clean, whitespace-based)
- Human Readability Moderate Poor High
- Native Comment Support No (prohibited by RFC 8259) Yes ( <!-- comment --> ) Yes ( # comment )
- Namespace Support No (simulated via key prefixes) Yes (native xmlns attribute) No
- Schema Validation JSON Schema (optional) XSD / DTD (robust, standardized) Kwalify / JSON Schema mapping
Primary Network Protocols REST APIs, RESTCONF, telemetry NETCONF, SOAP, legacy APIs Ansible, SaltStack, CI/CD, K8s
Python JSON Serialization and Deserialization
The Python standard library includes the json module, which converts between native Python objects (dictionaries, lists, booleans, strings) and JSON formatted text. Network engineers must understand the distinction between memory-based string operations and stream-based file operations: Python 'json' Module Function Architecture:
- In-Memory String Disk File Stream
- +-------------------------+ +-------------------------+
- | json.loads(json_str) | | json.load(file_handle) |
- | (JSON String -> Python) | | (File Stream -> Python) |
- +-------------------------+ +-------------------------+
- ^ ^
- | [ Deserialization / Parsing ] |
- =============+=================================+=============
- | [ Serialization / Encoding ] |
- v v
- +-------------------------+ +-------------------------+
- | json.dumps(py_obj) | | json.dump(py_obj, file) |
- | (Python -> JSON String) | | (Python -> File Stream) |
- +-------------------------+ +-------------------------+
- In-Memory Operations: json.loads() and json.dumps()
json.loads(string) (Load String): Takes a valid JSON string as input and deserializes it into corresponding Python objects (e.g., JSON objects become Python dict , JSON arrays become Python list , true becomes True , and null becomes None ). This function is used when parsing raw response bodies returned by HTTP libraries ( response.text ).
json.dumps(obj, indent=None, sort_keys=False) (Dump String): Takes a Python data structure and serializes it into a JSON formatted string. The indent argument specifies the number of spaces for indentation, producing "pretty-printed", human-readable formatting. Setting sort_keys=True sorts dictionary keys alphabetically, which is helpful when comparing configuration snapshots.
File-Based Operations: json.load() and json.dump()
json.load(file_pointer) : Reads a JSON document directly from an open file descriptor or stream and parses it into a Python data structure. Used when importing device inventories or local configuration parameters from disk.
json.dump(obj, file_pointer, indent=None) : Serializes a Python object and writes the resulting JSON text directly into an open file descriptor. Used when backing up device state or logging operational audit data.
Python json Module Functions Matrix
Function Direction Input Argument Type Return / Output Type Network Engineering Scenario
json.loads() Deserialization str or bytes (JSON) Python dict or list Parsing raw payload string from response.text
json.dumps() Serialization Python dict , list , etc. str (JSON text) Generating JSON payload string for REST POST/PUT
json.load() Deserialization File-like object ( .read() ) Python dict or list Loading device inventory from local devices.json
json.dump() Serialization Python object + File object None (writes to file) Persisting parsed controller data to disk files
Parsing Complex Nested JSON Controller Responses
Modern network controller responses are deeply nested structures combining dictionaries and lists. Consider a representative response from Cisco Catalyst Center's device inventory API ( /dna/intent/api/v1/network-device ): {
- "response": [
- {
- "hostname": "cat9300-access-01",
- "managementIpAddress": "10.10.20.81",
- "platformId": "C9300-48P",
- "reachabilityStatus": "Reachable",
- "softwareVersion": "17.9.4a",
- "upTime": "42 days, 06:12:30"
- },
- {
- "hostname": "cat9500-core-01",
- "managementIpAddress": "10.10.20.1",
- "platformId": "C9500-24Q",
- "reachabilityStatus": "Reachable",
- "softwareVersion": "17.9.4a",
- "upTime": "180 days, 12:45:10"
- }
- ],
- "version": "1.0"
- }
To parse this payload in Python, an engineer traverses the outer dictionary, navigates the embedded list under the "response" key, and queries specific fields on each device object: import json
# Simulating retrieval from disk or API
with open("catalyst_devices.json", "r") as f:
data = json.load(f) # Deserializes file into Python dictionary
- # Navigate nested list of device dictionaries
- device_list = data.get("response", [])
print(f"Discovered {len(device_list)} network devices:")
for dev in device_list:
- host = dev.get("hostname", "Unknown")
- ip = dev.get("managementIpAddress", "N/A")
- status = dev.get("reachabilityStatus", "N/A")
- version = dev.get("softwareVersion", "N/A")
if status == "Reachable":
print(f"[ONLINE] {host} ({ip}) - IOS XE {version}")
else:
print(f"[OFFLINE] {host} ({ip}) - Requires Investigation!")
Using .get() ensures that if an optional key is omitted from one of the device records, the script defaults gracefully rather than terminating with an unhandled exception.