Python JSON

Hello Heberto

Take a look at this lesson which deals with some parsing using JSON:

Now having said that, if you want to use a purpose-designed tool for this, you can use any of the following specialized libraries and tools:

  1. TextFSM: TextFSM is a Python module developed by Google which is widely used for parsing semi-structured text data like the output from “show” commands in Cisco IOS. It allows you to define a template that maps the output into a structured format, making it easier to process and analyze. TextFSM is particularly powerful for parsing complex and varied text outputs.

  2. Netmiko: While primarily a library for handling SSH connections to network devices, Netmiko can be used in conjunction with TextFSM to send commands and parse the output. Netmiko simplifies the process of connecting to a device, executing commands, and retrieving the output.

  3. PyATS/Genie: Developed by Cisco, PyATS is a Python automation framework designed specifically for network testing. Genie is part of the PyATS ecosystem and provides libraries for modeling and parsing network devices’ configurations and operational state. Genie can parse the output of “show” commands into structured JSON data, making it easier to work with programmatically.

  4. Nornir: Nornir is a pluggable multi-threaded framework with inventory management to help operate collections of devices. It can use Netmiko and other plugins to connect to devices, send commands, and parse the output.

  5. Ansible with ios_command module: Although Ansible is not a Python library per se, it is a powerful automation tool that can be used for network automation tasks. The ios_command module in Ansible allows you to run commands on remote Cisco IOS devices and can be used in conjunction with parsing filters to structure the output.

Each of these tools has its strengths, and the best choice may depend on the specific requirements of your project, such as the complexity of the data you’re dealing with, the scale of your network, and your familiarity with these tools. TextFSM is a great starting point for simple parsing tasks, while PyATS/Genie offers a more comprehensive solution for Cisco-specific environments. Netmiko and Nornir are excellent for broader automation tasks that include but are not limited to parsing command outputs.

I hope this has been helpful!

Laz