Interview Prep/Shell Scripting/find, xargs, jq and yq

How do you read structured log lines (JSON Lines) and filter by fields?

IntermediateConceptfind, xargs, jq and yq
Answer
# errors from the payments service in the last file, with timestamp and message
jq -r 'select(.level == "error" and .service == "payments") | "\(.ts) \(.msg)"' app.jsonl

# tolerate non-JSON lines mixed in
jq -R -r 'fromjson? | select(.status >= 500) | .path' app.log | sort | uniq -c | sort -rn

-R reads raw lines, fromjson? parses each and silently skips lines that are not valid JSON.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq