--json (or auto-emits JSON when piped). jq is the standard tool for slicing that JSON into the exact shape you need: a single field, a count, a CSV, a chart-ready projection. The snippets below cover the patterns that keep showing up in real scripts.
Prerequisites: authenticated CLI and
jq installed. On macOS, brew install jq. On Debian/Ubuntu, sudo apt install jq. On Windows, winget install jqlang.jq.The envelope
Every list command returns this shape:.data or .data[].
Project: pick specific fields
Extract a single field as a flat list
-r (raw output) strips JSON quotes so you get one email per line. Ready to pipe into mail, wc -l, or a follow-up CLI call.
Filter: keep rows that match
[ ... ] to collect the matches into an array. Drop the brackets for a stream of unwrapped objects.
Count
length on an array returns its size. pagination.totalElements returns the server-side total without pulling every page.
Group and count by company
// "Unknown" fallback keeps people without a company in the group instead of producing a null bucket.
Project to CSV
@csv quotes fields, escapes commas, and produces a valid CSV file. The first line is the header, the rest are rows.
Walk every page
jq -e exits non-zero when the test is false, so the loop stops the first time a page returns no rows. Streaming .data[] keeps every record on stdout for further piping.
Combine: count by company across all pages
jq -s (slurp) collects them back into a single array for the group-and-count step.
Read the error envelope
Tips
- Quote your jq filter in single quotes so the shell doesn’t expand
$characters before jq sees them. - Pass dynamic values with
--arg name value(string) or--argjson name value(parsed JSON). Inside the filter, reference them as$name. - Pretty-printed JSON is the default. Pass
-cfor one-record-per-line output that streams cleanly into other tools. - jq has a built-in
nowfunction.now | strftime("%Y-%m-%d")makes timestamped filenames trivial.
See also
- Output format. The JSON envelope every command returns.
- Recipe: New registrants this week. Uses
select,--arg, and@csvend-to-end. - Recipe: CSV import. Uses
jq -rto capture IDs from API responses. - Recipe: Channel analysis. Uses
--argjsonto combine multiple commands. - jq manual. The upstream reference.
