Pcornel
Browse topics
Options
Recent
Favorites
Networking · Technical reference

JSON & YAML Data

Direct answer

JSON and YAML represent structured data as nested objects (key/value maps) and lists. JSON is used by REST APIs; YAML, which is easier to read, is used for Ansible playbooks, inventories and configuration templates.

When to use this

Use it when writing API payloads, inventories or playbooks, or when a tool rejects a data file.

First 30 seconds

1. Parse it: jq . file.json or the YAML one-liner — error line?

2. JSON: missing quote, trailing comma or single quotes?

3. YAML: tabs or wrong indentation? yamllint.

4. Value changed type (no → false, 010 → 8)? Quote it.

5. Structure matches what the API or tool expects (object vs list)?

Operational verification

data written → parser accepts it → structure (objects, lists, types) matches the schema → tool or API consumes it → result as expected

Failure signatureYAML or JSON file is rejected by the tool

Ansible, a template or an API reports a parse error, or a value has the wrong type (for example "yes" becomes true).

Possible stored cause: Indentation, missing quotes or tabs break the structure, or YAML interprets unquoted values as booleans or numbers.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Cisco IOS / IOS XE
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformCisco IOS / IOS XE
Scope / prerequisiteUse it when writing API payloads, inventories or playbooks, or when a tool rejects a data file.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

4 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Ansible, a template or an API reports a parse error, or a value has the wrong type (for example "yes" becomes true).

Step 1 Verification & evidence Verify boundary

Validate syntax, inspect nesting and convert simple objects between representations.

Step 2 Common failure modes Narrow the fault

Indentation, quoting/type coercion, duplicate keys or assuming a string value is numeric/boolean.

Step 3 Troubleshooting workflow Narrow the fault

Focus for this topic: Indentation, quoting/type coercion, duplicate keys or assuming a string value is numeric/boolean.

Step 4 Common mistakes Narrow the fault
  • YAML indentation errors and tabs (YAML allows spaces only).
  • Unquoted values YAML interprets unexpectedly (no, on, 010).
  • Trailing commas in JSON.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Command lookup Jump straight to Cisco syntax
Key points

JSON: double quotes, no comments, no trailing commas. YAML: indentation with spaces (never tabs) defines structure; - starts a list item; quote values like yes, no, on and leading zeros, or YAML turns them into booleans or numbers. Both map directly to Python dicts and lists.

Key checks
  • python3 -m json.tool file.json / jq . file.json — JSON valid and pretty-printed.
  • python3 -c 'import yaml,sys; print(yaml.safe_load(open(sys.argv[1])))' file.yml — YAML parses to the expected structure.
  • yamllint file.yml — indentation and style errors.
  • jq '.items[].name' file.json — extract fields to check the structure.
ReferenceWhat it is1 section · depth on demand

Concept overview

Structured data representation used by APIs, inventories and automation systems.

Key ideas: JSON has explicit object/array/string/number/boolean/null structures; YAML is a human-friendly serialization often used for configuration/inventory.

ReferenceWhy it matters1 section · depth on demand

Why it matters

JSON has explicit object/array/string/number/boolean/null structures; YAML is a human-friendly serialization often used for configuration/inventory.

ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

JSON and YAML in automation

JSON is what APIs exchange, and YAML is what people write for inventories and variables. RFC 8259 defines JSON precisely:

  • Types: four primitive types (string, number, boolean, null) and two structured types (object, array).
  • Strings and literals: strings in double quotes, and lowercase literals true, false and null.
  • Numbers: no leading zeros, and no NaN or Infinity.
  • Objects: names should be unique within an object.
  • Exchange: UTF-8 without a byte order mark, with the media type application/json.

JSON has no comment syntax. YAML 1.2 aims to be a strict superset of JSON. It uses indentation with spaces (never tabs), supports comments with #, and has block scalars (| keeps line breaks, > folds them).

JSON and YAML side by side

FeatureJSON (RFC 8259)YAML 1.2
CommentsNoYes (#)
StructureBraces and bracketsIndentation, or flow style with braces and brackets
StringsAlways double-quotedQuotes usually optional
Multi-line textEscaped \nLiteral | or folded > blocks
ReuseNoAnchors & and aliases *
Typical useAPI payloads, responsesInventories, variables, playbooks

Pitfalls

PitfallExample
Trailing commas in JSON[110, 120,] is invalid
Tabs in YAML indentationA parse error
Unquoted values YAML interpretsLeading zeros, no/yes in YAML 1.1 parsers, MAC-like strings; quote them
Duplicate JSON keysBehaviour differs between parsers
dev$ cat vars/acc-2f-01.yml
hostname: acc-2f-01
mgmt_ip: 10.255.1.21
vlans:
  - { id: 110, name: USERS-2F }
  - { id: 120, name: VOICE-2F }
banner: |
  Authorised access only.
  Activity is logged.
dev$ python3 -c "import yaml, json; print(json.dumps(yaml.safe_load(open('vars/acc-2f-01.yml')), indent=2))"
dev$ yamllint vars/
dev$ python3 -m json.tool response.json > /dev/null && echo valid
dev$ jq '.response[] | {hostname, managementIpAddress}' devices.json

Converting YAML to JSON, as in the second command, is a quick way to see exactly what a YAML file means. It shows which values became numbers, booleans or strings. Use yaml.safe_load, not yaml.load, for files you didn't write yourself.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Quick reference

JSON and YAML are the two text formats used almost everywhere in network automation. JSON is what APIs send and receive; YAML is what people write for inventories, variables and playbooks because it is easier to read. They describe the same kinds of data, so converting between them is straightforward — as long as YAML's type-guessing quirks are kept in mind.

JSON and YAML represent the same structures (objects/mappings, arrays/lists, strings, numbers, booleans).

switches:
  - name: sw1
    vlans: [10, 20]
{"switches": [{"name": "sw1", "vlans": [10, 20]}]}
import json, yaml
data = yaml.safe_load(open("inventory.yml"))
print(json.dumps(data, indent=2))

YAML pitfalls: indentation is significant, unquoted yes/no/on/off may become booleans in YAML 1.1 parsers, and leading zeros or colons can change types — quote ambiguous values. Always use yaml.safe_load.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docCisco IOS / IOS XE Current documentation reviewed 2026-09-14

Authoritative/upstream documentation reviewed for bounded claims in Automation and Artificial Intelligence → JSON & YAML Data. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.cisco.com/c/en/us/support/ios-nx-os-software/ios-xe-17/series.html · confidence 94%
Depth when you need it

Deep reference

Design & tradeoffs

ENCOR design tradeoffs

Structured data should preserve schema/intent; human readability does not remove the need for validation.

Confirmation

Confirm action

Continue?