Task 05 — Parse JSON with jq
Write a script 05.sh that reads a JSON file and prints the email of every user with "active": true, one email per line, in array order.
Submit as
05.sh
Input
| Source | Format |
|---|---|
| CLI | ./05.sh <data.json> — path to a JSON file |
| JSON file | Single object with a users array. Each element is an object with at least email (string) and active (boolean). Extra fields (id, name, …) may be present. |
{
"users": [
{"id": 1, "email": "[email protected]", "name": "Alice", "active": true},
{"id": 2, "email": "[email protected]", "name": "Bob", "active": false}
]
}
Output
| Stream | Format |
|---|---|
| stdout | One line per matching user: the email string only (no quotes, no JSON). Only users with active == true. Order matches the order in the users array. Trailing newline after the last line is fine. |
| stderr | Not checked |
| Exit code | 0 on success |
Example
Input data.json:
{ "users": [
{"email": "a@x", "active": true},
{"email": "b@x", "active": false},
{"email": "c@x", "active": true}
] }
stdout:
a@x
c@x
What the grader checks
Visible (5 pts) — exit 0 (2 pt) plus each active email present (1 pt each). On miss: expected line vs got.
Hidden (4 pts) — pass/fail only: stdout must match the fixture exactly (order, no extra lines).
Hints
jq -r '.users[] | select(.active == true) | .email'