Network automation lab 2 of 27
Data formats: JSON, XML and YAML in Python
Read the same interface data as JSON, XML and YAML, parse each into identical Python structures, avoid the classic YAML traps, then do it again with live RESTCONF data from an IOS XE router.
Run this lab
It needs Lite: its 2 nodes are set to 2 vCPU and 5,120 MB in total. That fits the free demo too.
In your workspace: Shared, then Network Automation - CCNA and CCNP Automation guided labs, then 02 - Data formats - JSON XML and YAML in Python
- Level
- Beginner
- Time
- About 60 minutes
- Nodes need
- 2 vCPU, 5,120 MB
- Smallest plan
- Lite
The scenario
Kestrel Freight's tools disagree about formats: the new controller speaks JSON, NETCONF answers in XML, and the team writes its inventory and variables in YAML. Before anyone writes automation that changes devices, you'll make sure everyone can read all three formats into the same Python data, and you'll catch the YAML values that quietly mean something other than what they look like. Then you'll prove it on live data from the IOS XE router xe1.
| Device | Role | Address |
|---|---|---|
| devbox | Automation workstation | 10.10.20.10/24 |
| xe1 | IOS XE 17.3 router (RESTCONF on HTTPS) | 10.10.20.21/24 (Gi1) |
Files in ~/lab/data: interfaces.json, interfaces.xml and interfaces.yaml (the same four interfaces of a router called lon-wan-01) and inventory.yaml (a colleague's draft). Your code goes in ~/lab/formats.py, which has a TODO for each parser. Device login: netops / NetOps-Lab1.
What you’ll practise
- Compare JSON, XML and YAML: objects and lists, data types, namespaces and comments
- Parse JSON with json, XML with ElementTree (including namespaces) and YAML with yaml.safe_load
- Spot YAML values that change type silently (versions, times, leading zeros, NO) and fix them with quotes
- Normalise data from different formats into one Python structure and write it back as JSON and YAML
- Fetch and interpret real RESTCONF replies in JSON and XML
The tasks
- Compare the three formats
- Parse JSON
- Parse XML, namespaces included
- Parse YAML, and defuse its traps
- Normalise everything and write it back out
- Read live RESTCONF data from xe1
The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.
Topology and devices
The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.
Every link, as text
- devbox
eth0to Mgmt (network) - xe1
Gi1to Mgmt (network)
| Node | Device | Image in Add Node | Set to |
|---|---|---|---|
| devbox | EVE-NG GUI server (Docker) | eve-gui-server:latest | 1 vCPU, 1,024 MB |
| xe1 | Cisco CSR 1000v | csr1000vng-universalk9.17.03.08a-serial | 1 vCPU, 4,096 MB |
How to open this lab
Sign in to your workspace at
lab.cloudlabbox.com.In File Manager, open Shared, then the folder
Network Automation - CCNA and CCNP Automation guided labs.Open
02 - Data formats - JSON XML and YAML in Pythonand start its nodes, then open Lab Tasks for the scenario and the steps.
The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.
More Network automation labs
Related labs in other courses
CloudLabBox is independent of Cisco. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.