Domain 2 of 4 · Chapter 7 of 7

YAML/JSON from YANG Models

Unlock the complete study guide + 1,040 practice questions across 16 full exams.

Bundled into the existing Designing, Deploying and Managing Network Automation Systems premium course — no separate purchase.

14-day money-back guarantee — no questions asked.

Included in this chapter:

  • Two specifications, one data model
  • Four node types, four JSON/YAML shapes
  • Leaf values: when a number is a string
  • Namespace-qualified names: module in JSON, URI in XML
  • Constructing a body from the model
  • Reading the 350-901 stem

YANG node type to JSON/YAML construct

Propertyleafleaf-listcontainerlist
JSON constructtyped scalararray of scalarsobject { }array of objects [ { } ]
YAML constructscalarsequence of scalarsmappingsequence of mappings
Carriesone valuemany valueschild nodesmany like entries
Key leaf requiredn/anonoyes
Common mis-encoding64-bit int as bare numbersingle value not in an arraywrapped in an arrayemitted as one object

Decision tree

Node carries a value or child nodes? Value node: one or many? Structure node: one or many entries? a value child nodes leaf to typed scalar leaf-list to array of scalars container to object { } list to array of [ { } ] one many one many Always: a list is an array even with one entry; int64 / uint64 / decimal64 leaves encode as JSON strings.

Cheat sheet

  • RFC 7951 defines YANG-to-JSON encoding
  • Namespace-qualified member names
  • Identityref values are module-qualified
  • JSON qualifies by module name; XML by namespace URI
  • A container maps to a JSON object
  • A list maps to a JSON array of keyed objects
  • A leaf maps to a typed scalar
  • List entries must carry their key leaf
  • YAML and JSON serialize the same structure
  • The body's top-level object matches the URL target node
  • Nesting must mirror the YANG tree exactly
  • pyang -f tree reveals the required structure

Unlock with Premium — includes all practice exams and the complete study guide.

References

  1. https://www.rfc-editor.org/rfc/rfc7951
  2. https://www.rfc-editor.org/rfc/rfc8040
  3. https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
  4. https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/prog/configuration/1715/b_1715_programmability_cg/m_1715_prog_restconf.html
  5. https://www.rfc-editor.org/rfc/rfc7950
  6. https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/prog/configuration/174/b_174_programmability_cg/restconf_protocol.html
  7. https://www.rfc-editor.org/rfc/rfc6241
  8. https://www.rfc-editor.org/rfc/rfc8340