JNCIA-DevOps Practice Question: An automation engineer is writing a Python script that takes a complex nested Python…
An automation engineer is writing a Python script that takes a complex nested Python dictionary containing Junos telemetry parameters and converts it into a YAML string. Which PyYAML function should be used?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
yaml.safe_dump()
yaml.safe_dump() converts a Python object into a YAML-formatted string safely, avoiding the security risks associated with the base yaml.dump().
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
yaml.export()
Why it's wrong here
PyYAML has no yaml.export() function. Converting a dictionary to a YAML string is done with yaml.dump(), which handles nested structures directly. The export naming resembles other serialisation libraries, which makes it tempting, but it is absent from PyYAML's API.
- ✗
yaml.serialize_string()
Why it's wrong here
yaml.serialize_string() is not a PyYAML function; the library provides yaml.dump() and yaml.safe_dump() for converting Python objects into YAML text. The name sounds plausible because serialisation is the task, but no such method exists in the module.
- ✗
yaml.to_yaml()
Why it's wrong here
PyYAML exposes no yaml.to_yaml() function; the module's serialisation entry point is yaml.dump(), which writes a Python object to a YAML stream or string. A to_yaml-style helper exists in other libraries, making the name tempting, but it is not part of PyYAML's API.
- ✓
yaml.safe_dump()
Why this is correct
yaml.safe_dump() serialises Python objects to YAML while restricting output to standard safe types, preventing arbitrary object instantiation. This satisfies the constraint of converting a nested dictionary of telemetry parameters into a YAML string without exposing the script to unsafe deserialisation risks.
About these practice questions
Courseiva writes every JNCIA-DevOps question from scratch — 273 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
You might also like
Similar JNCIA-DevOps questions
- Which TWO features are supported by YAML but are notably absent in standard JSON? (Choose two)
- When serializing complex nested Python dictionaries to JSON, which THREE data types will cause a TypeError unless handle…
- When writing an automation script that converts data formats between YAML and JSON for Junos configuration pipelines, wh…
- An automation script reads a configuration template where boolean values are represented as 'yes' and 'no' in YAML. When…
- When serializing Python data structures to JSON for Junos automation payloads, which THREE parameters can be passed to j…
Written and reviewed by Johnson Ajibi, MSc IT Security
Security Systems Architect · founder of Courseiva
Last reviewed August 2026 · checked against the official Juniper Networks exam blueprint
This JNCIA-DevOps practice question is part of Courseiva's free Juniper Networks certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the JNCIA-DevOps exam.