YANG leaf vs leaf-list: single value versus keyless collection
Short answer
A Leaf holds exactly one value, while leaf-list holds multiple same-typed, unkeyed scalar values, so selecting A preserves the one-value-versus-keyless-array distinction.
Question
Key Takeaways
In YANG, a leaf stores exactly one typed value, whereas a leaf-list stores multiple values of the same type without keys or entry identity. Option A captures that scalar-versus-array distinction, while keyed repetition belongs to the YANG list construct rather than to a leaf-list. That cardinality and keyless rule is why A is correct for the difference between leaf and leaf-list.
Expert Analysis
Because a YANG leaf carries exactly one value while a leaf-list carries an ordered set of same-typed values with no key of its own, option A is the only description that matches the data-model semantics.
RFC 7950 defines leaf as single-valued and leaf-list as a keyless collection
In the YANG schema, leaf and leaf-list are both leaf nodes in the data tree, but they have different cardinality contracts. A leaf is a node that holds exactly one value of its declared type; it can have a default, be mandatory, or be optional, but it cannot hold two instances of that value. A leaf-list is a node that holds zero or more values of one declared type, and those values are an ordered collection defined by the schema, not keyed entries with independent identity. RFC 7950 makes the key rules explicit: a key statement is allowed only on a list, and it names one or more leaf children of that list, not leaf-list children. The schema tree therefore treats leaf as a terminal scalar node and leaf-list as a terminal collection node, not as a nested container with entry children. That is why option C fails at the schema level: leaf-list is not the construct used to define list keys. The distinction is structural, not cosmetic. leaf answers 'what single value does this property have?' whereas leaf-list answers 'which values of this property are present?' Both can be used inside a container or a list, but only the former can be a key leaf under a keyed list.
Option A states the scalar-versus-array contract that the module enforces
The decisive wording is the pairing of 'one value' with leaf and 'multiple unkeyed scalar values' with leaf-list. That is not a loose analogy; it is the cardinality distinction a YANG compiler checks. A module that declares leaf hostname { type string; } permits one hostname string. A module that declares leaf-list dns-server { type inet:ip-address; } permits zero, one, or many DNS server addresses in a single leaf-list node. The word 'unkeyed' is equally important: it rules out the list-entry interpretation that would require a key statement and per-entry child nodes. Neither declaration creates keyed list entries, and neither needs a key statement. Option B collapses the two constructs, which would make it impossible to tell whether a JSON payload should carry a string or an array. Option C moves the key concept onto leaf-list, but keys belong to list entries and are declared with key using child leaf nodes. Option D reverses the relationship by saying leaf is for lists, when a leaf is simply a scalar property that may sit inside a list. Only option A preserves the exact cardinality and keyless nature that YANG uses to separate these nodes.
Keyed list entries explain why leaf-list cannot serve as a list key
The concept most easily confused with leaf-list is the list. A list can contain multiple entries, and each entry can have a distinct identity because one or more child leaf nodes are named in the list's key statement. The key argument itself is a string that references leaf identifiers, so a leaf-list identifier in that position is invalid rather than merely unusual. A leaf-list is not a list of entries: it has no entry boundaries, no per-entry children, and no key of its own. That boundary makes option C untenable in a concrete way. If a model defines list server { key name; leaf name { type string; } leaf-list tag { type string; } }, then name is a key leaf, while tag is a keyless leaf-list of strings; the tag values cannot identify a server entry. Option D confuses a leaf with a list container by implying that leaf exists 'for lists.' A leaf can be a child of a list, a child of a container, a key leaf, or a top-level scalar, but it never supplies list semantics by itself. The correct boundary is: list equals repeated keyed entries; leaf-list equals repeated values without keys; leaf equals one value.
Serialization shows leaf-list as an array and leaf as a single value
The distinction becomes visible at the encoding stage, which is where option A actually takes effect. In a JSON payload generated from a YANG model, a leaf is represented by a member whose value is the scalar itself, such as 'hostname': 'edge-1'. A leaf-list is represented by a member whose value is an array, such as 'dns-server': ['192.0.2.10', '192.0.2.11'], even when only one value is present. In XML, the same contrast appears as a single element with text content versus repeated elements for the leaf-list. In an RFC 8340 tree diagram, a leaf-list is marked with * after its name while a plain leaf is not, giving a quick visual check. This encoding step is also why a payload cannot be validated by counting names alone: the schema tells the receiver whether a given name expects a scalar or an array. A receiver that expected a scalar for a leaf-list name would reject the array, and a receiver that expected an array for a leaf name would reject the scalar, which is exactly the validation boundary the schema supplies. A tool such as YANG Suite or pyang derives that expectation from the module, so the model, not the instance document, decides whether the value is a single leaf or a keyless leaf-list.
Official Reference
- https://datatracker.ietf.org/doc/html/rfc7950#section-7.6
- https://datatracker.ietf.org/doc/html/rfc7950#section-7.7
- https://datatracker.ietf.org/doc/html/rfc8340
These links open the official vendor documentation in a new tab.
Exam Strategy
When an item contrasts two YANG nodes, classify each as scalar, collection, or keyed entry before reading the option labels. Ask whether the construct can carry a key: only a list entry can, and its keys are named leaf children. Then visualize the JSON encoding—single value versus array—to eliminate options that merge leaf and leaf-list. This cardinality-and-key test transfers to any YANG schema or RFC 8340 tree item.
Related Analysis
Practice All 300-435 Questions
Access 150 questions with complete answers and detailed explanations.
View Full 300-435 Practice Test →