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

Try it free for 30 minutesRun it on Lite from £3 a day

The free demo needs no card and no email. Every lab plan includes every guided lab.

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.

DeviceRoleAddress
devboxAutomation workstation10.10.20.10/24
xe1IOS 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

  1. Compare the three formats
  2. Parse JSON
  3. Parse XML, namespaces included
  4. Parse YAML, and defuse its traps
  5. Normalise everything and write it back out
  6. 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.

Topology of Data formats - JSON XML and YAML in Python2 nodes and 1 network, 2 links. Every link is listed as text below the diagram.devboxxe1Mgmteth0Gi1
2 nodes and 1 network, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in Data formats: JSON, XML and YAML in Python, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
devboxEVE-NG GUI server (Docker)eve-gui-server:latest1 vCPU, 1,024 MB
xe1Cisco CSR 1000vcsr1000vng-universalk9.17.03.08a-serial1 vCPU, 4,096 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Network Automation - CCNA and CCNP Automation guided labs.

  3. Open 02 - Data formats - JSON XML and YAML in Python and 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

All 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.