jq Filter Reference
The most commonly used jq expressions, with examples you can click to load directly into the playground.
Identity & Field Access
| Filter | Description | Example output |
|---|---|---|
| . | Identity — returns the input unchanged | The full input |
| .key | Extract a field from an object | .name → "Alice" |
| .key.nested | Access nested fields | .user.address.city |
| .["key"] | Access fields with special characters | .["first-name"] |
| .key? | Extract field, return null if missing (no error) | .missing? → null |
Arrays
| Filter | Description | Example |
|---|---|---|
| .[] | Iterate all elements of an array or object | Streams each element |
| .[0] | Get element by index (negative counts from end) | .[-1] → last item |
| .[2:5] | Slice from index 2 to 4 | Returns 3 elements |
| length | Number of elements in array, characters in string | [1,2,3] | length → 3 |
| first | First element of an array | Same as .[0] |
| last | Last element of an array | Same as .[-1] |
| reverse | Reverse the order of an array | [3,1,2] | reverse → [2,1,3] |
| unique | Remove duplicate values | [1,2,1] | unique → [1,2] |
| flatten | Flatten nested arrays | [[1,[2]],3] | flatten → [1,2,3] |
| min / max | Minimum or maximum value in an array | [3,1,2] | max → 3 |
| min_by(.f) / max_by(.f) | Min/max by a field | min_by(.age) |
| add | Sum numbers, concatenate strings or arrays | [1,2,3] | add → 6 |
| indices("x") | All indices where value appears | "abab" | indices("a") → [0,2] |
Transformation
| Filter | Description | Example |
|---|---|---|
| map(f) | Apply filter to each element, return array | map(.name) → ["Alice","Bob"] |
| map_values(f) | Apply filter to each value in object | map_values(. * 2) |
| select(cond) | Keep elements where condition is true | .[] | select(.age > 18) |
| sort | Sort a simple array | [3,1,2] | sort → [1,2,3] |
| sort_by(.f) | Sort array of objects by a field | sort_by(.name) |
| group_by(.f) | Group elements by a field value | group_by(.role) |
| unique_by(.f) | Remove duplicates by field | unique_by(.id) |
| to_entries | Convert object to [{key, value}] array | {"a":1} | to_entries |
| from_entries | Convert [{key, value}] back to object | Inverse of to_entries |
| with_entries(f) | to_entries | map(f) | from_entries | Transform key/value pairs |
| keys | Get array of object keys, sorted | {"b":2,"a":1} | keys → ["a","b"] |
| values | Get array of object values | {"a":1} | values → [1] |
| has("key") | Test if object has a key | has("name") → true/false |
| in(obj) | Test if value is a key in obj | "name" | in({"name":1}) |
| contains(x) | Test if input contains x | [1,2,3] | contains([2]) |
Pipes & Composition
| Filter | Description | Example |
|---|---|---|
| f | g | Pipe output of f into g | .users | map(.name) |
| f, g | Produce outputs from both f and g | .a, .b |
| [f] | Collect all outputs of f into an array | [.[] | .name] |
| {a: .x, b: .y} | Construct a new object | {name: .name, age: .age} |
| empty | Produce no output (useful with select) | Filters out values |
| not | Boolean negation | select(.active | not) |
| type | Get the type of a value | "hello" | type → "string" |
| tostring | Convert value to a JSON string | 42 | tostring → "42" |
| tonumber | Convert string to number | "42" | tonumber → 42 |
| ascii_downcase | Lowercase a string | "HELLO" | ascii_downcase |
| ascii_upcase | Uppercase a string | "hello" | ascii_upcase |
| ltrimstr("x") / rtrimstr("x") | Remove prefix / suffix from string | "foobar" | ltrimstr("foo") → "bar" |
| split("x") / join("x") | Split string / join array into string | "a,b" | split(",") → ["a","b"] |
| test("regex") | Test if string matches regex | "foo" | test("f.*") → true |
Common jq Recipes
Extract a field from every object in an array
Given a JSON array of users, get all names:
[.[] | .name]
# or equivalently:
map(.name)
Filter an array by condition
Keep only active admins:
.[] | select(.active == true and .role == "admin")
Reshape objects
Create a new object with only the fields you need:
map({ id: .id, fullName: .name, isAdmin: (.role == "admin") })
Sort and deduplicate
# Sort by age, oldest first
sort_by(.age) | reverse
# Remove duplicates by email
unique_by(.email)
Group and count
# Group users by role, count each group
group_by(.role) | map({ role: .[0].role, count: length })
Extract nested values safely
# Returns null instead of error if path is missing
.user?.address?.city?
Frequently Asked Questions
What is jq?
jq is a lightweight command-line tool for processing JSON. It lets you extract fields, filter arrays, transform objects, and reshape data with a concise filter syntax. This playground runs jq-compatible filters directly in your browser — no install needed.
How do I extract a field with jq?
Use .fieldName to extract a top-level field. For example, .name returns the value of the name key. For nested fields, chain with dots: .user.address.city. For arrays, use .[] to iterate all elements or .[0] to get the first.
How do I filter an array with jq?
Use select() inside a pipe: .[] | select(.age > 18) returns only elements where age is greater than 18. You can combine conditions: .[] | select(.active == true and .role == "admin").
How do I sort a JSON array with jq?
Use sort to sort a simple array, or sort_by(.field) to sort an array of objects by a specific property. Add | reverse to flip the order. Example: sort_by(.age) | reverse sorts oldest-first.
Does this jq playground support all jq features?
It supports the most common operations: field access, array iteration, pipes, map(), select(), sort_by(), group_by(), keys, values, length, unique, reverse, first, last, min, max, and more. Advanced features like @base64, try-catch, and recursive descent (..) are not supported. For full jq, use the official jq tool.
Is my JSON data uploaded anywhere?
No. All jq filtering runs locally in your browser using JavaScript. Your JSON never leaves your device.
Need to lint or fix your JSON first?
If your JSON has syntax errors — trailing commas, single quotes, comments, missing brackets — use the JSON Linter and Fixer to repair it before filtering.