JQ examples
Practical, runnable jq snippets. Click any example to open it in the interactive jq playground, then edit the JSON input and the expression to see results instantly.
Use jq select() to filter an array of JSON objects by an attribute value. Interactive example that keeps only objects whose field matches a given value.
Sort a JSON array by a field using jq sort_by(). Interactive example showing how to sort objects ascending, then reverse for descending order.
Group an array of JSON objects by a field with jq group_by(). Interactive example that buckets records by a shared key and collects their values.
Count items per group in jq by combining group_by() with length. Interactive example that counts how many records fall into each group.
Sum a numeric field per group in jq by combining group_by() with add. Interactive example that totals values within each group.
Convert a JSON object into an array of {key, value} pairs with jq to_entries. Interactive example for iterating over objects with dynamic keys.
Build a JSON object from an array of {key, value} pairs with jq from_entries. Interactive example that rebuilds an object keyed by a chosen field.
Transform every key or value of a JSON object with jq with_entries. Interactive example that rewrites object keys in a single pass.
Transform each element of a JSON array with jq map(). Interactive example that reshapes and renames fields for every object in an array.
Transform every value of a JSON object with jq map_values(). Interactive example that reshapes each value while preserving the object keys.
Define reusable helper functions in jq with def. Interactive example showing how to declare a function and apply it inside a pipeline.
Branch on values in jq with if / elif / else / end. Interactive example that maps input values to different results using conditional logic.