Tools
Get Pro

Free tutorial

Learn jq

jq is the command-line tool for slicing, filtering and reshaping JSON. These lessons go from the first . to reduce and recursive search. Every example shows its real output and opens in the jq Playground, where you can change it — it runs jq 1.8 in your browser, so nothing is uploaded.

  1. Lesson 1jq basics: get fields and nested valuesLearn the jq basics with runnable examples: the identity filter, getting a field, nested fields, keys with spaces and the optional ? operator.
  2. Lesson 2jq arrays: index, slice, iterate and lengthWork with JSON arrays in jq: get the first or last item, slice a range, iterate with .[], collect results back into an array and count items.
  3. Lesson 3jq select(): filter arrays by valueFilter JSON arrays with jq select(): match a field value, combine conditions with and/or, compare numbers, test strings and keep the result an array.
  4. Lesson 4jq map() and map_values()Transform every item of a JSON array with jq map(), or every value of an object with map_values(). Runnable examples with fields, math and filters.
  5. Lesson 5jq: build new objects and pick fieldsCreate JSON objects with jq: pick a few fields, rename keys, use computed keys, merge objects with + and * and turn arrays into lookup objects.
  6. Lesson 6jq -r: raw output without quotesPrint plain strings from jq with -r (raw output): remove quotes, output one value per line, join with a separator and build text lines with interpolation.
  7. Lesson 7Convert JSON to CSV with jqConvert a JSON array to CSV or TSV with jq: @csv and @tsv, a header row, nested fields, arrays inside cells and the -r flag you must not forget.
  8. Lesson 8jq group_by: group and count itemsGroup a JSON array by a field with jq group_by, count items per group, sum a value per group and turn the result into an object or a sorted list.
  9. Lesson 9jq sort_by, unique_by, min_by and max_bySort JSON arrays in jq with sort and sort_by (ascending, descending, several keys), remove duplicates with unique_by and find the min or max item.
  10. Lesson 10jq keys, to_entries and with_entriesWork with object keys in jq: list keys, check a key exists, loop over key/value pairs with to_entries, and filter or rename keys with with_entries.
  11. Lesson 11jq if-then-else and default valuesWrite conditions in jq: if-then-elif-else-end, the // alternative operator for defaults, type checks, try-catch for errors and empty to skip values.
  12. Lesson 12jq strings: test, contains, split and interpolationString functions in jq with examples: interpolation, contains and startswith, regex test and capture, split and join, case, trim and sub/gsub replace.
  13. Lesson 13jq: add, update and delete fieldsModify JSON with jq: set a value with =, update in place with |=, += for math, add new fields, delete keys with del() and redact values at any depth.
  14. Lesson 14jq recursive search: find a key at any depthSearch deeply nested JSON with jq: the recursive descent operator .., find every value of a key, list all paths, flatten nested objects and use getpath.
  15. Lesson 15jq reduce, slurp and NDJSON (JSON Lines)Process many JSON values with jq: NDJSON / JSON Lines input, -s slurp into one array, -c compact output, reduce for running totals and add to sum.
  16. Lesson 16jq variables: as $x, --arg and $ENVUse variables in jq: bind with as $x, pass shell values safely with --arg and --argjson, read environment variables with $ENV and define functions.

Already know the basics?

The jq cheat sheet has every filter on one page, andJSONPath is a simpler query language if you only need to select values.