Courseiva

EX294 Transform data with filters and plugins Practice Question

A playbook registers the output of a command that returns a JSON string inside stdout. The string contains a top-level key 'services' with a nested list of dictionaries. You need to convert that string into native data so you can select only entries where the 'state' key equals 'running'. Which expression accomplishes this?

⚠ Common exam trap

The trap here is assuming selectattr can filter dictionaries nested under a key without first dereferencing that key in the expression.

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

✓

{{ (command_result.stdout | from_json).services | selectattr('state', 'equalto', 'running') | list }}

Parsing the JSON string with from_json is required before any attribute-based filtering can occur. Once parsed, the nested list must be dereferenced through the 'services' key. Only then can selectattr compare each dictionary's 'state' value to 'running' and return the matching subset as a list.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    {{ (command_result.stdout | from_json).services | selectattr('state', 'equalto', 'running') | list }}

    Why this is correct

    The from_json filter parses the stdout string into native data, then the '.services' lookup reaches the nested list. Applying selectattr to that list with equalto 'running' returns only matching dictionaries. The final list filter materializes a real list instead of a generator, which is important for templating and iteration.

  • ✗

    {{ command_result.stdout | from_json | selectattr('state', 'equalto', 'running') | list }}

    Why it's wrong here

    This converts the JSON string correctly, but selectattr operates on a list of top-level items, not on the nested list under 'services'. Because the parsed data is a dictionary, selectattr will fail or return nothing useful. The nested list must first be reached with a key lookup before filtering by the 'state' attribute.

  • ✗

    {{ command_result.stdout | from_json | map(attribute='services') | selectattr('state', 'equalto', 'running') | list }}

    Why it's wrong here

    The map filter with attribute='services' expects each item in a list to have that attribute. Here the parsed data is a dictionary, not a list, so map does not extract the nested list. Even if it did, selectattr would then run against the list object rather than its dictionaries, so the filtering would not match entries by 'state'.

  • ✗

    {{ command_result.stdout | to_json | selectattr('state', 'equalto', 'running') | list }}

    Why it's wrong here

    to_json serializes data into a JSON string rather than parsing it. Applying selectattr to a string is invalid and does not produce filtered dictionaries. This option confuses serialization with deserialization, so it cannot reach the nested 'services' list or evaluate the 'state' key in the scenario.

About these practice questions

Courseiva writes every EX294 question from scratch — 392 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 →

How Courseiva writes practice questions · Editorial policy

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 Red Hat exam blueprint

This EX294 practice question is part of Courseiva's free Red Hat 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 EX294 exam.