pyang -f tree Output: RFC 8340 YANG Tree Diagrams

300-435 By islever Editorial Last updated

Short answer

A The `pyang -f tree` formatter emits a YANG tree diagram per RFC 8340, not JSON, Python code, or HTML documentation.

Question

What does pyang -f tree generate?
  1. YANG tree diagram per RFC 8340 Correct Answer
  2. JSON output
  3. Python code
  4. HTML docs

Key Takeaways

pyang's -f tree formatter renders a YANG module as an RFC 8340 tree diagram, showing schema branches, config/state flags, and node types in plain text. Option A is correct because the tree format plugin produces that diagram, not JSON, Python, or HTML. JSON or generated code would come from a different formatter or tool, so the flag itself fixes the output type.

Expert Analysis

Because pyang -f tree names the tree formatter and supplies it with a YANG module, the command emits the RFC 8340 textual tree rendering — option A — rather than a JSON payload, Python code, or HTML documentation.

Pyang's tree formatter is an RFC 8340 rendering, not a data encoder

Pyang is a YANG compiler and validator, and its output is chosen by a format plugin rather than by the module being processed. The tree format plugin walks the resolved schema tree and prints a compact, human-readable diagram using the notation standardized in RFC 8340: the module name at the top, branches drawn with +--, data nodes marked rw for configuration or ro for state, list keys identified, leaf types shown, and augments or groupings reflected in how the schema is assembled. This is a schema view, not an instance document: it tells an engineer which containers, lists, leaves, choices and RPCs exist and how they nest, but it does not carry values for a particular device. That distinction matters because a YANG module can be rendered in several ways — YANG text, YIN XML, tree notation, or a JSON representation of schema or data depending on the plugin — and -f tree selects exactly one of those renderings. RFC 8340 defines the tree syntax itself, including conventions for config/state, keys, mandatory nodes and augmentations, so option A is the direct description of the artifact. The output is plain text, suitable for terminal review, documentation review, or diffing module revisions; it is not a data payload and not executable code.

The -f tree flag fixes the output format before any module content is considered

The decisive element is the literal format argument. pyang requires a module and accepts -f (or --format) to select a formatter; once tree is passed, the choice is made at the command line, independent of whether the module contains containers, lists, identities, or notifications. A JSON artifact would require a JSON-oriented formatter or a separate tool that serializes schema or instance data, and such output would be JSON text with braces, keys and values — not RFC 8340 branch notation. Python code would require a code generator, not pyang's tree printer. HTML documentation would require a documentation or HTML plugin, or a separate doc pipeline; the tree printer does not emit markup, stylesheets or hyperlinks. The command's wording is therefore narrow: it names the tree formatter, not what pyang can generate in general. Option A matches the formatter's name and the standard it implements. Options B, C and D each name an artifact produced by a different stage, plugin or tool, so they fail even though pyang can participate in workflows that eventually produce JSON payloads, code, or documentation. The flag is the controlling condition, and it points to a tree diagram.

Tree diagrams describe schema shape while JSON carries encoded data or schema

The conflation to avoid is between a model's structure and a serialized encoding. A tree diagram answers "what nodes exist and how are they arranged?" — for example, it shows an interfaces container containing an interface list keyed by name, with leaves for description and enabled. A JSON payload answers "what values are being sent or returned?" — for example, {"ietf-interfaces:interfaces": {"interface": [{"name": "GigabitEthernet1", "enabled": true}]}} — and is what a RESTCONF client might POST or what a NETCONF or RESTCONF response might encode, depending on the protocol and media type. RFC 8340 tree notation has no braces, quoted keys or value assignments; it uses branch characters and flags to communicate cardinality, config/state status, keys, and type names. Python code is another artifact entirely: it is executable logic that may use a library to build or parse JSON, but the tree printer does not generate functions or classes. HTML docs are presentation markup, not schema notation. Thus option B is not a "more detailed" version of the tree; it belongs to a different layer, the encoded data or schema serialization layer. The tree is most useful before payload construction: it helps an engineer identify the correct path, list key and leaf type that a JSON payload must respect.

Format selection inside pyang's emission stage is where -f tree takes effect

Mechanically, pyang first parses the module, resolves imports and includes, validates statements, and builds an internal schema tree; only after that does the selected output plugin traverse the tree and emit text. The tree plugin is the emitter: it starts at the module root, recurses through child nodes, and writes one line per schema node with prefix characters that encode nesting and status. That is the precise point where the RFC 8340 artifact is created. No device connection, NETCONF session, RESTCONF request or data instance is involved, so the command cannot return live interface counters or configured values. If an engineer expects JSON from pyang -f tree, the fix is to change the formatter or use the appropriate serialization tool, not to alter the YANG module. If the tree looks wrong, the investigation belongs in module resolution, augments, deviations or the plugin version, because those affect the schema tree before emission. This stage also explains why redirecting stdout to a .txt file is the normal way to capture the diagram for review; the bytes are plain tree notation, and downstream parsing should target that notation rather than JSON.

Official Reference

These links open the official vendor documentation in a new tab.

Exam Strategy

When a CLI command specifies an output flag, isolate that formatter or mode before reasoning about the underlying data model: -f tree names the tree printer, so the expected artifact is the RFC 8340 diagram. Eliminate choices that describe a different artifact — JSON payload, Python code, or HTML docs — because each requires a different plugin or tool. Also map the output to its purpose: tree diagrams for reading schema shape, JSON for RESTCONF payloads.

Practice All 300-435 Questions

Access 150 questions with complete answers and detailed explanations.

View Full 300-435 Practice Test →

← Back to 300-435 Study Guide