Cisco Certified Support Technician (CCST) NetworkingAutomation and ProgrammabilityMedium

A network automation script is designed to retrieve configuration data from a network device using its REST API. The script needs to parse the received data, which is formatted as JSON, and extract specific values from nested objects. Which programming construct is commonly used in languages like Python to access elements within a JSON object?

  1. ARegular expressions
  2. BDot notation or dictionary keys
  3. CSQL queries
  4. DXPath expressions
Show answer & explanation

Correct answer: B. Dot notation or dictionary keys

When JSON data is parsed into a programming language like Python, it is typically converted into a dictionary (or an object in other languages). Elements within this dictionary can then be accessed using dot notation (for objects/attributes) or square bracket notation with dictionary keys (for dictionary entries).

Why the other options are wrong

  • A. Regular expressions are used for pattern matching in text, which can be overly complex and error-prone for structured JSON data parsing compared to native JSON parsers.
  • C. SQL queries are for interacting with relational databases, not for parsing JSON data in a script.
  • D. XPath expressions are primarily used for navigating and selecting nodes in XML documents, not JSON.

JSON Parsing (Python)

The process of converting a JSON string into native Python data structures (dictionaries and lists), allowing for programmatic access and manipulation of the data.

  • JSON objects map to Python dictionaries
  • JSON arrays map to Python lists
  • Elements accessed via keys (dictionaries) or indices (lists)

Memory trick: JSON is like a dictionary, use keys to find values.

More Automation and Programmability questions