Data Formats: JSON, XML, and YAML
APIs and automation tools exchange data in a structured format. Three dominate networking: JSON, XML, and YAML. Knowing how each stores an object, a list, and a key/value pair is what lets you read an API response or write a config file.
Why a data format?
When a script asks a controller for a device, the reply must be something both sides can parse unambiguously. A human-readable sentence will not do. A data format defines the rules for writing structured data — objects with named fields, lists of items, and typed values — so that any program can read it back reliably. The three you must know are JSON, XML, and YAML.
The underlying data never changes — only the notation does. JSON uses quoted keys with braces and brackets; XML uses angle-bracket tags; YAML uses indentation and leading dashes. Recognising the notation is the whole skill.
JSON
JSON (JavaScript Object Notation) is the most common format in modern network APIs. It is built from just two structures:
- An object — a set of key/value pairs wrapped in curly braces
{ }. Keys are always strings in double quotes. - An array — an ordered list wrapped in square brackets
[ ].
{
"hostname": "SW1",
"management_ip": "10.0.0.5",
"enabled": true,
"uplinks": 2,
"vlans": [10, 20, 30],
"interface": {
"name": "GigabitEthernet1/0/1",
"mode": "access",
"vlan": 10
}
}
JSON supports a small set of data types: strings ("SW1"), numbers (2, 10.5), booleans (true/false), null, and the two container types (object and array). Notice that objects and arrays can nest freely: the interface key holds another object, and vlans holds an array of numbers.
| Type | Example | Notes |
|---|---|---|
| String | "access" | Always double-quoted. |
| Number | 2, 10.5 | No quotes. |
| Boolean | true / false | Lowercase, no quotes. |
| Null | null | Means “no value”. |
| Object | { "name": "SW1" } | Key/value pairs. |
| Array | [10, 20, 30] | Ordered list. |
hostname: "SW1" (single quotes or unquoted key) is not valid JSON — a classic trick question.XML
XML (eXtensible Markup Language) represents the same kind of data using tags. A value sits between an opening and a closing tag, and nesting is shown by containment.
<device>
<hostname>SW1</hostname>
<management_ip>10.0.0.5</management_ip>
<enabled>true</enabled>
<vlans>
<vlan>10</vlan>
<vlan>20</vlan>
</vlans>
<interface name="GigabitEthernet1/0/1" mode="access"/>
</device>
XML has two ways to store a piece of data: as the content between tags (<hostname>SW1</hostname>) or as an attribute inside the opening tag (name="GigabitEthernet1/0/1"). Elements must nest correctly and every tag must close. XML is more verbose than JSON, but it supports comments and schemas and is still used by older APIs and by NETCONF, which carries XML configuration.
<hostname>SW1</hostname>. An attribute is a name="value" pair inside a tag, such as mode="access".YAML
YAML (YAML Ain’t Markup Language) is a human-friendly format widely used for configuration files, including Ansible playbooks. It uses indentation instead of braces or closing tags. A map (object) is a set of key: value lines; a list is a set of lines beginning with a dash.
hostname: SW1 management_ip: 10.0.0.5 enabled: true vlans: - 10 - 20 interface: name: GigabitEthernet1/0/1 mode: access
YAML’s minimal punctuation makes it very readable, but that same reliance on whitespace is its weakness: a wrong indent changes the meaning, and tabs are forbidden. YAML is excellent for configuration that humans write and read; it is less common as the wire format for an API response, where JSON’s explicit braces are less error-prone to generate.
Comparing the three
| JSON | XML | YAML | |
|---|---|---|---|
| Style | Braces/brackets, quoted | Tags and attributes | Indentation, dashes |
| Verbosity | Medium | High | Low |
| Human-readable | Good | Fair | Excellent |
| Typical use | REST API responses | NETCONF, legacy APIs | Ansible/config files |
| Comments | No | Yes | Yes (#) |
| Data types | Explicit (string/number/bool/null) | Mostly text | Explicit |
A handy way to keep them apart: JSON uses quotes and braces, XML uses angle-bracket tags, YAML uses indentation and dashes. If you are shown a snippet, the first character or two almost always gives the format away — a { means JSON, a < means XML, and a bare key: at the start of a line means YAML.
It also helps to know where each format appears in the automation chain. YAML is usually the input you write as an operator (Ansible playbooks, config files). JSON is usually the data in flight across a REST API, produced and consumed by programs. XML is the older wire format still spoken by NETCONF and some vendor APIs, and it is the one you are most likely to encounter with legacy equipment. Recognising which stage of the pipeline a snippet belongs to tells you a lot about what a tool is doing with it.
Why JSON dominates REST
JSON has become the default for REST APIs, including network controllers, for several practical reasons:
- Compact — far less overhead than XML’s closing tags, which matters when data volumes are large.
- Native to JavaScript — browsers and JavaScript servers parse it directly, and every modern language (Python included) has a fast built-in JSON library.
- Clear data types — numbers stay numbers and booleans stay booleans, so a client does not have to guess whether
"2"is text. - Directly maps to program objects — a JSON object becomes a dictionary and a JSON array becomes a list, so parsing is trivial.
- Human-friendly enough — readable without special tooling, unlike the tag noise of XML for simple data.
None of this makes XML obsolete — NETCONF still models configuration in XML, and YAML is the language of Ansible. But when you call a REST API this week, the body you send and receive will almost certainly be JSON, which is why the next lesson is devoted to reading it.
Review
Check what you have learned with these review questions.
| Key term | Meaning |
|---|---|
| Data format | A defined structure for writing data so programs can parse it reliably. |
| JSON | JavaScript Object Notation; objects (key/value) and arrays, with explicit data types. |
| Object | A set of key/value pairs in JSON, wrapped in curly braces. |
| Array | An ordered list of values, wrapped in square brackets. |
| Key/value pair | A named field and its value, the basic unit of a JSON object. |
| XML | Markup format using nested elements and attributes. |
| Element | An XML tag pair with content, e.g. <hostname>SW1</hostname>. |
| Attribute | An XML name="value" pair inside an opening tag. |
| YAML | Indentation-based format for configuration files (maps and lists). |
- Cisco. CCNA (200-301) Exam Topics, Domain 6.0 Automation and Programmability. cisco.com.
- ECMA International. ECMA-404: The JSON Data Interchange Syntax. ecma-international.org.
- Bray, T. et al. RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format (2017). rfc-editor.org/rfc/rfc8259.
- W3C. Extensible Markup Language (XML) 1.0. w3.org/TR/xml.
- YAML. YAML Ain’t Markup Language Specification. yaml.org/spec.
Sources & references
- Cisco. CCNA (200-301) Exam Topics, Domain 6.0 Automation and Programmability. cisco.com.
- ECMA International. ECMA-404: The JSON Data Interchange Syntax. ecma-international.org.
- Bray, T. et al. RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format (2017). rfc-editor.org/rfc/rfc8259.
- W3C. Extensible Markup Language (XML) 1.0. w3.org/TR/xml.
- YAML. YAML Ain’t Markup Language Specification. yaml.org/spec.
Target exams: CCNA 200-301 v1.1 · CyberOps Associate 200-201. Last content verification: 2026-10-11.