JSON & YAML Explained for Network Engineers
JSON and YAML are the two data formats network automation runs on — APIs return JSON, Ansible playbooks are written in YAML. Both structure data as key-value pairs and lists; JSON is compact and machine-oriented, YAML is human-friendly and readable.
The same data, two formats
JSON uses braces and quotes: {"vlan": 10, "name": "SALES"}. YAML uses indentation: vlan: 10 newline name: SALES. They're interchangeable in meaning — tools convert freely between them. JSON dominates API responses; YAML dominates human-written config (playbooks, pipelines) because indentation is easier to read than nested braces.
Why they matter for automation
When you query a device's REST API, it returns JSON your Python script parses into a dictionary. When you write an Ansible playbook, you write YAML. Understanding both — key-value pairs, lists, nesting — is the foundation for reading API docs and writing automation. It's explicitly on the CCNP automation blueprint.
Common mistakes
YAML is indentation-sensitive — mixing tabs and spaces, or misaligning by one space, breaks a playbook with cryptic errors (use spaces, be consistent). JSON is strict about trailing commas (not allowed) and requires double quotes. A JSON/YAML validator catches both instantly.
Frequently asked questions
What is the difference between JSON and YAML?
Both structure the same kind of data (key-value pairs, lists); JSON uses braces/quotes and suits machines/APIs, while YAML uses indentation and is more human-readable, favoured for config files.
Why do network engineers need to know JSON and YAML?
APIs return data as JSON and automation tools like Ansible use YAML — reading and writing both is essential for network automation and modern device management.
Is YAML indentation really that important?
Yes — YAML is indentation-sensitive; inconsistent spaces or tabs cause failures. Always use spaces consistently and validate before running.
Can JSON and YAML be converted to each other?
Yes — they represent equivalent data structures, and tools/libraries convert freely between them.
Related articles
Want hands-on training?
Learn this on real Cisco lab devices with placement support at Attila Technologies, Ahmedabad.