Week 12 · Lesson 6

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.

CCNA 200-301 Domain 6.0 Automation and Programmability Verified 2026-10-11
Part 1

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 same device, three notations · select a format

      

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.

Part 2

JSON

JSON (JavaScript Object Notation) is the most common format in modern network APIs. It is built from just two structures:

{
  "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.

TypeExampleNotes
String"access"Always double-quoted.
Number2, 10.5No quotes.
Booleantrue / falseLowercase, no quotes.
NullnullMeans “no value”.
Object{ "name": "SW1" }Key/value pairs.
Array[10, 20, 30]Ordered list.
Exam tip. In JSON, keys are always double-quoted strings and the separator between key and value is a colon. Strings use double quotes, never single quotes. A response with hostname: "SW1" (single quotes or unquoted key) is not valid JSON — a classic trick question.
The six JSON types · pick one

Part 3

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.

Definition — XML element vs attribute. An element is a tag pair with content, such as <hostname>SW1</hostname>. An attribute is a name="value" pair inside a tag, such as mode="access".
Part 4

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.

Note. YAML is a superset of JSON in theory — valid JSON is usually valid YAML — but in practice the two look very different. Do not confuse YAML’s dashes-and-indent style with JSON’s braces-and-brackets style on an exam.
Part 5

Comparing the three

JSONXMLYAML
StyleBraces/brackets, quotedTags and attributesIndentation, dashes
VerbosityMediumHighLow
Human-readableGoodFairExcellent
Typical useREST API responsesNETCONF, legacy APIsAnsible/config files
CommentsNoYesYes (#)
Data typesExplicit (string/number/bool/null)Mostly textExplicit

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.

Identify the format · work through the snippets
Snippet 1 of 5

      

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.

Part 6

Why JSON dominates REST

JSON has become the default for REST APIs, including network controllers, for several practical reasons:

Exam tip. If asked why JSON is preferred for REST, the expected reasons are that it is lighter/more compact than XML, easy for machines and humans to read, has native data types, and is natively supported by JavaScript and Python. “Because it is encrypted” or “because it is a protocol” are wrong.
Which format belongs where · select a stage

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.

Part 7 · Your turn

Review

Check what you have learned with these review questions.

Review · 6 questions

Key termMeaning
Data formatA defined structure for writing data so programs can parse it reliably.
JSONJavaScript Object Notation; objects (key/value) and arrays, with explicit data types.
ObjectA set of key/value pairs in JSON, wrapped in curly braces.
ArrayAn ordered list of values, wrapped in square brackets.
Key/value pairA named field and its value, the basic unit of a JSON object.
XMLMarkup format using nested elements and attributes.
ElementAn XML tag pair with content, e.g. <hostname>SW1</hostname>.
AttributeAn XML name="value" pair inside an opening tag.
YAMLIndentation-based format for configuration files (maps and lists).
Sources & references
  1. Cisco. CCNA (200-301) Exam Topics, Domain 6.0 Automation and Programmability. cisco.com.
  2. ECMA International. ECMA-404: The JSON Data Interchange Syntax. ecma-international.org.
  3. Bray, T. et al. RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format (2017). rfc-editor.org/rfc/rfc8259.
  4. W3C. Extensible Markup Language (XML) 1.0. w3.org/TR/xml.
  5. YAML. YAML Ain’t Markup Language Specification. yaml.org/spec.
Sources

Sources & references

  1. Cisco. CCNA (200-301) Exam Topics, Domain 6.0 Automation and Programmability. cisco.com.
  2. ECMA International. ECMA-404: The JSON Data Interchange Syntax. ecma-international.org.
  3. Bray, T. et al. RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format (2017). rfc-editor.org/rfc/rfc8259.
  4. W3C. Extensible Markup Language (XML) 1.0. w3.org/TR/xml.
  5. 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.