Use it when writing API payloads, inventories or playbooks, or when a tool rejects a data file.
JSON & YAML Data
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.
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)?
data written → parser accepts it → structure (objects, lists, types) matches the schema → tool or API consumes it → result as expected
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
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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 · 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.
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.
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,falseandnull. - 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
| Feature | JSON (RFC 8259) | YAML 1.2 |
|---|---|---|
| Comments | No | Yes (#) |
| Structure | Braces and brackets | Indentation, or flow style with braces and brackets |
| Strings | Always double-quoted | Quotes usually optional |
| Multi-line text | Escaped \n | Literal | or folded > blocks |
| Reuse | No | Anchors & and aliases * |
| Typical use | API payloads, responses | Inventories, variables, playbooks |
Pitfalls
| Pitfall | Example |
|---|---|
| Trailing commas in JSON | [110, 120,] is invalid |
| Tabs in YAML indentation | A parse error |
| Unquoted values YAML interprets | Leading zeros, no/yes in YAML 1.1 parsers, MAC-like strings; quote them |
| Duplicate JSON keys | Behaviour 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.
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.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%Deep reference
Design & tradeoffs
ENCOR design tradeoffs
Structured data should preserve schema/intent; human readability does not remove the need for validation.