JQ Expression Syntax for Creating Filters

This section describes common JQ syntax elements you can use to create filter conditions.

JQ Filter Description JSON Sample Result
[.[]]
Selects all elements of an array.
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]
[.[] | .field]
Selects a specific field from each object in an array.
[{ "field": "value1" }, { "field": "value2" }]
["value1", "value2"]
[.[] | select(.field == "value")]
Filters elements where a specific field equals a value.
[{ "field": "value1" }, { "field": "value2" }]
[{ "field": "value1" }]
map(has("field"))
Extracts the results of a specific function applied.
[{ "field": "value1" }, { "field": "value2" }]
[true, true]
[.[] | .field | select(. == "value")]
Filters elements of an array where a specific field equals a value.
[{ "field": "value" }, { "field": "value1" }]
["value"]
[.[] | select(length > 5)]
Filters elements with a length greater than 5.
["apple", "banana", "orange", "grape"]
["banana", "orange"]
[.[] | select(.field1 == "value" and .field2 > 10)]
Selects elements where both conditions are true.
[{"field1": "value", "field2": 15}, {"field1": "value", "field2": 20}]
[{"field1": "value", "field2": 15}, {"field1": "value", "field2": 20}]
[.[] | select(.field1 == "value" or .field2 > 10)]
Selects elements where at least one of the conditions is true.
[{"field1": "value", "field2": 5}, {"field1": "other_value", "field2": 15}]
[{"field1": "value", "field2": 5}, {"field1": "other_value", "field2": 15}]
[.[] | select(.field1 == "value" and .field2 < 10)]
Selects elements where both conditions are true.
[{ "field1": "value", "field2": 5 }, { "field1": "other_value", "field2": 15 }]
[{"field1": "value", "field2": 5}]
[.[] | select(.field1 == "value" and (.field2 > 10 or .field3 == "include"))]
Combines and and or conditions to filter elements where the first condition is true and either the second condition is true or the third condition is include.
[{"field1": "value", "field2": 5, "field3": "include"}]
[{"field1": "value", "field2": 5, "field3": "include"}]
[.[] | select(.field1 != "value")]
Selects elements where the field1 is not equal to value.
[{ "field1": "other_value", "field2": 15 }, { "field1": "value", "field2": 5 }]
[{"field1": "other_value", "field2": 15}]
[.[] | select(.field1 == "value" and (.field2 > 10 and .field3 == "include"))]
Combines and conditions to filter elements where the first condition is true and both the second and third conditions are true.
[{"field1": "value", "field2": 15, "field3": "include" }]
[{"field1": "value", "field2": 15, "field3": "include"}]
[.[] | select(.field1 == "value" or (.field2 > 10 and .field3 == "include"))]
Combines or conditions to filter elements where either the first condition is true or both the second and third conditions are true.
[{"field1": "other_value", "field2": 15, "field3": "include" }, { "field1": "value", "field2": 5, "field3": "include" }]
[{"field1": "other_value", "field2": 15, "field3": "include"}], [{"field1": "value",
 "field2": 5, "field3": "include"}]
[.[] | select(.field1 == "value" and .field2 > 10 and .field3 != "exclude")]
Combines multiple and conditions to filter elements where all conditions are true.
[{ "field1": "value", "field2": 15, "field3": "include" }]
[{"field1": "value", "field2": 15, "field3": "include"}]
[.[] | select(.field1 != "value" and (.field2 <= 10 or .field3 == "exclude"))]
Combines not and or conditions to filter elements where field1 is not equal to value and either field2 is less than or equal to 10 or field3 is exclude.
[{"field1": "other_value", "field2": 5, "field3": "exclude"}]
[{"field1": "other_value", "field2": 5, "field3": "exclude"}]
.[]|.foo>30 and .bar== "less interesting data"|.==true
Returns exactly true while executing rather than returning the values.
[{"foo": 42, "bar": "less interesting data"}]
true