echo '[10,20,30]' | jq 'first'`first` returns the first item from an array or stream.
Deep reference for jq arrays, objects, grouping, entries, path updates, reshaping, and structural manipulation.
Indexing, slicing, mapping, and searching arrays.
echo '[10,20,30]' | jq 'first'`first` returns the first item from an array or stream.
echo '[10,20,30]' | jq 'last'`last` returns the final item.
echo '[10,20,30]' | jq 'nth(1)'Useful when you prefer function form over indexing syntax.
echo '["a","b","c"]' | jq 'index("b")'Returns the first matching index or null.
echo '["a","b","c"]' | jq 'contains(["b"])'`contains()` works for arrays and objects.
echo '[{"active":false},{"active":true}]' | jq 'any(.[]; .active)'`any()` is concise for boolean checks across collections.
echo '[{"active":true},{"active":true}]' | jq 'all(.[]; .active)'`all()` verifies complete compliance across the array.
echo '[1,2,3,4]' | jq 'reverse'Useful for display order and last-first style reports.
Inspect object fields and values.
echo '{"a":1,"b":2}' | jq 'values'Use when you want to ignore keys and work with values only.
echo '{"b":2,"a":1}' | jq 'keys_unsorted'Useful when you want original key order rather than sorted order.
echo '{"a":1}' | jq 'type'Returns values like `object`, `array`, `string`, `number`, and `boolean`.
echo '{"id":1,"name":"alice","email":"a@example.com","role":"admin"}' | jq '{id, name, role}'Ideal for reducing noisy API payloads.
echo '{"first":"Alice","last":"Ng","team":"eng"}' | jq '{user: {full_name: (.first + " " + .last)}, meta: {team}}'jq object construction supports arbitrary expressions as values.
echo '{"role":"admin","active":true}' | jq 'contains({role: "admin"})'Very useful for policy and config checks.
Turn objects into entry arrays and back again.
echo '{"a":1,"b":2}' | jq 'map_values(. * 10)'`map_values()` is concise when only object values need changing.
echo '{"a":1,"b":3,"c":5}' | jq 'to_entries | map(select(.value >= 3)) | from_entries'A classic pattern for object filtering.
echo '{"first_name":"Alice","last_name":"Ng"}' | jq 'to_entries | map(.key |= gsub("_"; "-")) | from_entries'Great for adapting between naming conventions.
echo '[{"id":"u1","name":"alice"},{"id":"u2","name":"bob"}]' | jq 'map({key: .id, value: .name}) | from_entries'Convenient for building lookup tables.
echo '[{"team":"eng","name":"a"},{"team":"eng","name":"b"},{"team":"ops","name":"c"}]' | jq 'group_by(.team) | map({key: .[0].team, value: map(.name)}) | from_entries'Excellent for reporting and reshaping lists into keyed groups.
Edit or inspect nested structures by path.
echo '{"user":{"profile":{"name":"alice"}}}' | jq 'getpath(["user","profile","name"])'Useful when paths are built dynamically.
echo '{}' | jq 'setpath(["user","profile","name"]; "alice")'`setpath()` can create intermediate objects as needed.
echo '{"user":{"password":"secret","token":"abc","name":"alice"}}' | jq 'delpaths([["user","password"],["user","token"]])'Very useful for scrubbing sensitive fields.
echo '{"user":{"name":"alice","roles":["admin","dev"]}}' | jq 'paths(scalars)'Great for data profiling and flattening strategies.
echo '{"user":{"name":"alice","roles":["admin","dev"]}}' | jq '.. | scalars'Recursive descent plus `scalars` is a good way to inspect content quickly.
echo '{"items":[{"name":"a"},{"child":{"name":"b"}}]}' | jq '.. | objects | select(has("name"))'The recursive descent operator `..` is powerful for document-wide search.
Summaries, counts, and report-style reductions.
echo '[{"status":"ok"},{"status":"fail"},{"status":"ok"}]' | jq 'group_by(.status) | map({status: .[0].status, count: length})'One of the most useful jq reporting patterns.
echo '[{"amount":10},{"amount":15},{"amount":5}]' | jq 'map(.amount) | add'Map to the field first, then aggregate.
echo '[{"score":80},{"score":90},{"score":100}]' | jq '(map(.score) | add) / length'Simple but common analytics pattern.
echo '[{"name":"a","age":20},{"name":"b","age":35}]' | jq '{youngest: min_by(.age), oldest: max_by(.age)}'`min_by()` and `max_by()` are very handy for summaries.
echo '[{"name":"a","active":true},{"name":"b","active":false}]' | jq '{active: map(select(.active)), inactive: map(select(.active | not))}'Useful for dashboards and summary reports.