Skip to content

Quiz: jq / JSON Processing

← Back to quiz index

5 questions

L0 (2 questions)

1. How do you extract all pod names from kubectl output using jq?

Show answer kubectl get pods -o json | jq -r '.items[].metadata.name'

2. How do you filter kubectl JSON output for pods in CrashLoopBackOff?

Show answer kubectl get pods -o json | jq -r '.items[] | select(.status.containerStatuses[]?.state.waiting?.reason == "CrashLoopBackOff") | .metadata.name'

L1 (2 questions)

1. How do you use jq to merge two JSON objects and handle key collisions?

Show answer Use the * operator: jq -n '{a:1, b:2} * {b:3, c:4}' produces {a:1, b:3, c:4}. The right-hand side wins on collisions. For arrays, use + to concatenate. For deep merge, use * recursively.

2. How do you use jq select() with multiple conditions?

Show answer Chain with 'and'/'or': jq '.items[] | select(.status == "Running" and .metadata.namespace == "prod")'. Parentheses group conditions. select() passes the input through if the expression is truthy, drops it otherwise.

L2 (1 questions)

1. How do you reshape JSON with jq to produce a CSV-like output from nested data?

Show answer Use @csv with an array: jq -r '.items[] | [.metadata.name, .status.phase, .spec.nodeName] | @csv'. The -r flag outputs raw strings (no outer quotes). Use @tsv for tab-separated. For headers, prepend a static array before the data rows.