XK0-006 Automation, Orchestration, and Scripting Practice Question
A configuration-management script must take a YAML inventory file and convert it into JSON so a downstream API can consume it, preserving all nested structure. Which command accomplishes this most directly?
⚠ Common exam trap
The trap here is assuming a general-purpose text tool can convert between structured data formats when only a format-aware parser preserves nesting.
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
✓
yq -o=json '.' inventory.yaml
Structured conversion requires a tool that understands YAML syntax, and yq does exactly that by parsing the document and emitting JSON when given the -o=json flag. Text utilities such as sed, grep, and awk operate line by line and cannot reconstruct nested maps and sequences, so they inevitably corrupt the data the API expects.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
awk -F': ' '{print $2}' inventory.yaml
Why it's wrong here
Splitting on colon-space and printing the second field loses keys and flattens nesting, and lines without a colon produce empty output. Indented sub-keys are treated as ordinary lines, so the resulting stream is unstructured text rather than JSON. awk is field-based and has no concept of YAML document structure.
- ✗
grep -E '^[a-zA-Z]+:' inventory.yaml
Why it's wrong here
This only prints top-level keys that begin a line, discarding all values, indentation, and nested content. The output is a list of key names, not a structured document, so the API would receive incomplete data. grep performs pattern matching rather than parsing, so it cannot preserve hierarchy.
- ✓
yq -o=json '.' inventory.yaml
Why this is correct
The yq utility parses YAML natively and its -o=json output flag re-serializes the whole document as JSON, keeping nested maps and lists intact. The identity filter '.' selects the entire document, so this single command produces valid JSON that the API can consume without any intermediate text manipulation.
- ✗
sed 's/:/=/g' inventory.yaml
Why it's wrong here
This replaces every colon with an equals sign, producing neither valid YAML nor valid JSON and destroying the key-value delimiters. It also cannot represent nested lists or multi-line blocks correctly, so the downstream API would receive malformed data. sed is a line-oriented text editor, not a structured-format converter.
Go deeper
Related to this question
About these practice questions
Courseiva writes every XK0-006 question from scratch — 781 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 →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official CompTIA exam blueprint
This XK0-006 practice question is part of Courseiva's free CompTIA 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 XK0-006 exam.