jq '.' file.jsonPretty prints the entire JSON content to standard output with syntax highlighting.
Example
jq '.' access_log.jsonA lightweight command-line JSON processor: filter, transform and pretty-print JSON from APIs, logs and tool output.
sudo apt install jqjq '.key' file.jsonExtracts the value of a specific key from the root object.
Example
jq '.status' response.jsonjq '.foo.bar' file.jsonAccesses a nested key using dot notation.
Example
jq '.user.profile.id' users.jsonjq '."complex-key"' file.jsonAccesses keys containing special characters or hyphens using quotes.
Example
jq '."Content-Type"' headers.jsonjq '.foo?' file.jsonSuppress errors if the field does not exist (null safety).
Example
jq '.error?' logs.jsonjq '.[0]' file.jsonExtracts the first element of an array.
Example
jq '.[0]' items.jsonjq '.[-1]' file.jsonExtracts the last element of an array.
Example
jq '.[-1]' updates.jsonjq '.[1:4]' file.jsonSlices an array, returning elements from index 1 up to (but not including) 4.
Example
jq '.[1:4]' list.jsonjq '.[]' file.jsonIterates over an array or object values, unpacking them into a stream.
Example
jq '.users[]' users_list.jsonjq 'length' file.jsonReturns the length of a string, array, or object.
Example
jq '.items | length' cart.jsonjq -r '.key' file.jsonOutputs raw strings without quotes, useful for shell piping.
Example
jq -r '.token' auth.jsonjq 'map(.id)' file.jsonTransforms an array by applying a filter to every element.
Example
jq 'map(.id)' objects.jsonjq 'select(.id > 100)' file.jsonFilters output, keeping only elements where the condition is true.
Example
jq 'map(select(.age >= 18))' users.jsonjq 'select(.status == "active")' file.jsonFilters stream for objects matching a specific string value.
Example
jq '.users[] | select(.role == "admin")' users.jsonjq 'select(.error != null)' file.jsonSelects objects where a specific field is not null.
Example
jq 'select(.retry_count != 0)' jobs.jsonjq 'split(",")' file.jsonSplits a string into an array based on a delimiter.
Example
jq '.tags | split(",")' posts.jsonjq 'join(", ")' file.jsonJoins an array of strings into a single string with a separator.
Example
jq '.permissions | join(" | ")' roles.jsonjq 'ascii_downcase' file.jsonConverts string input to lowercase.
Example
jq '.email | ascii_downcase' contacts.jsonjq 'contains("str")' file.jsonChecks if a string contains a specific substring.
Example
jq 'select(.message | contains("Error"))' logs.jsonjq 'test("regex")' file.jsonTests if a string matches a regular expression pattern.
Example
jq 'select(.ip | test("^192\.168"))' network.jsonjq 'match("regex")' file.jsonReturns detailed match object including captures and offsets.
Example
jq '.version | match("^[0-9]+")' package.jsonjq 'capture("regex")' file.jsonCaptures named groups from a regex into a JSON object.
Example
jq '.log | capture("(?<level>[A-Z]+): (?<msg>.+)")' syslog.jsonjq 'sort' file.jsonSorts an array of scalars or objects.
Example
jq '.tags | sort' metadata.jsonjq 'sort_by(.key)' file.jsonSorts an array of objects based on a specific field.
Example
jq 'sort_by(.timestamp)' events.jsonjq 'group_by(.key)' file.jsonGroups array elements into subarrays based on a field value.
Example
jq 'group_by(.category)' products.jsonjq 'unique' file.jsonRemoves duplicates from an array and sorts it.
Example
jq '.visited_urls | unique' history.jsonjq 'unique_by(.key)' file.jsonRemoves objects with duplicate values for a specific key.
Example
jq 'unique_by(.id)' users.jsonjq 'min' file.jsonFinds the minimum value in an array.
Example
jq '[.items[].price] | min' catalog.jsonjq 'max' file.jsonFinds the maximum value in an array.
Example
jq '[.scores[]] | max' results.jsonjq 'add' file.jsonSums the numbers in an array.
Example
jq '[.invoices[].total] | add' finance.jsonjq 'if .a then .b else .c end' file.jsonImplements standard if-then-else conditional logic.
Example
jq 'if .admin then "superuser" else "user" end' auth.jsonjq '.a // .b' file.jsonUses the Alternative Operator to provide default values if preceding values are null or false.
Example
jq '.display_name // .username // "Anonymous"' profile.jsonjq '.key = "value"' file.jsonAssigns a new static value to a field.
Example
jq '.status = "processed"' task.jsonjq '.count += 1' file.jsonIncrements a numeric value using update assignment.
Example
jq '.login_attempts += 1' user.jsonjq '.tags += ["new"]' file.jsonAppends an element to an existing array.
Example
jq '.roles += ["auditor"]' user.jsonjq 'del(.key)' file.jsonDeletes specified keys from an object.
Example
jq 'del(.password, .secret)' config.jsonjq '(.values[]) |= . + 1' file.jsonUpdates every element in an array in place.
Example
jq '(.prices[]) |= . * 1.1' menu.jsonjq -s '.' file.jsonSlurps all input JSON objects into a single large array.
Example
jq -s '.' part1.json part2.jsonjq -R '.' file.txtReads input as raw strings instead of JSON.
Example
jq -R '.' raw_logs.txtjq -n '{a: 1}'Uses null input, useful for generating JSON from scratch without an input file.
Example
jq -n '{timestamp: now}'jq --arg name val '.'Passes a value from the shell into a jq variable.
Example
jq -n --arg env "prod" '{environment: $env}'jq 'now' file.jsonReturns the current time as a Unix timestamp.
Example
jq '{check_time: now}' status.jsonjq 'todate' file.jsonConverts a Unix timestamp to an ISO 8601 string.
Example
jq '.timestamp | todate' log.jsonjq 'fromdate' file.jsonConverts an ISO 8601 string to a Unix timestamp.
Example
jq '.iso_time | fromdate' data.jsonjq 'strflocaltime("%Y-%m-%d")' file.jsonFormats a timestamp using standard strftime format strings.
Example
jq 'now | strflocaltime("%H:%M:%S")' file.jsonjq '@base64'Encodes the input string to Base64.
Example
jq '.payload | @base64' secret.jsonjq '@base64d'Decodes a Base64 string.
Example
jq '.encoded | @base64d' data.jsonjq '@csv'Formats an array as a CSV row.
Example
jq '.users[] | [.id, .name] | @csv' users.jsonjq '@tsv'Formats an array as a Tab-Separated Value row.
Example
jq '.logs[] | [.time, .msg] | @tsv' logs.jsonjq '@uri'Percent-encodes a string for use in URLs.
Example
jq '.search_query | @uri' request.jsonjq '@sh'Escapes a string for safe use in a shell command.
Example
jq '.filename | @sh' config.jsonjq 'debug' file.jsonPrints the current input to stderr for debugging purposes without affecting output.
Example
jq 'map(debug) | .[]' list.jsonjq 'reduce .[] as $item (0; . + $item)'Reduces an array to a single value (e.g., sum) using an accumulator.
Example
jq 'reduce .prices[] as $p (0; . + $p)' cart.jsonjq 'reduce inputs as $i (.; . + [$i])'Processes a stream of inputs efficiently without loading everything into memory.
Example
jq -n 'reduce inputs as $line (0; . + ($line|length))' file.txtjq 'recurse(.children[])'Recursively visits a structure defined by a path.
Example
jq 'recurse(.sub_departments[])' org_chart.jsonjq 'walk(if type == "object" then del(.null_keys) else . end)'Applies a function to every node in the JSON tree recursively.
Example
jq 'walk(if type == "string" then ascii_upcase else . end)' data.jsonjq 'env'Accesses system environment variables as a JSON object.
Example
jq -n 'env.HOME'jq '. as $root | .items[] | select(.id == $root.target)'Defines a variable within jq to reference data from a different context.
Example
jq '.threshold as $t | .values[] | select(. > $t)' data.jsonjq --argjson data '{"a":1}'Passes a JSON string from the shell and parses it into a jq variable.
Example
jq --argjson config '{"debug": true}' '$config.debug'jq --slurpfile dict dict.jsonReads a secondary file into a variable array for lookups or joining.
Example
jq --slurpfile blacklist bad_ips.json 'select(.ip as $ip | $blacklist | index($ip) | not)' access.jsonjq 'type' file.jsonReturns the type of the value (object, array, string, number, null, boolean).
Example
jq 'map(type)' mixed_array.jsonjq 'select(type == "string")'Filters input based on JSON data type.
Example
jq '.[] | select(type == "number")' data.jsonjq 'arrays, objects, scalars'Built-in filters to select only arrays, objects, or scalar values.
Example
jq 'arrays' mixed_stream.jsonjq '"Name: \(.name), ID: \(.id)"'Uses string interpolation to embed expressions inside strings.
Example
jq '"Value: \(.value * 100)%"' stats.jsonjq 'import "module" as mod'Imports a jq library file from the search path.
Example
jq -L. 'import "utils" as u; u::func' main.jsonjq -e . file.jsonSets the shell exit code based on the output (0 if result is not null/false, 1 otherwise).
Example
jq -e '.success' response.jsonaws ec2 describe-instances | jq '.Reservations[].Instances[].InstanceId'Extracts specific resource IDs from complex Cloud API responses.
Example
cat instances.json | jq -r '.[].InstanceId'jq -R 'split(" ") | {time:.[0], method:.[3], url:.[4]}'Parses raw text logs into JSON structure using manual splitting.
Example
cat access.log | jq -R 'split(" ") | {ip: .[0]}'jq -s 'group_by(.level) | map({level: .[0].level, count: length})'Aggregates log entries to count occurrences of specific event levels.
Example
jq -s 'group_by(.status) | map({status:.[0].status, count:length})' logs.jsonjq 'select(.timestamp > (now - 3600))'Filters logs to show only entries from the last hour (or specific duration).
Example
jq 'select(.time_sec > (now - 86400))' events.jsonjq 'select(.headers["User-Agent"] | contains("curl"))'Identifies automated bot traffic by analyzing User-Agent strings.
Example
jq 'select(.ua | contains("python-requests"))' access_log.jsonjq 'select(.response_code >= 500)'Filters for server-side errors or client errors in web logs.
Example
jq 'select(.status >= 400)' http_log.jsonjq '.Records[] | select(.eventName == "ConsoleLogin" and .errorMessage != null)'Detects failed console login attempts in CloudTrail logs.
Example
jq '.records[] | select(.event == "DeleteBucket")' cloudtrail.jsonjq -r '. | select(.resources[] | contains("sg-12345"))'Searches for events related to a specific compromised or target resource ID.
Example
jq 'select(.resource_id == "i-abcde")' config_history.jsonjq 'del(.. | .password?, .secret?, .token?)'Recursively scrubs sensitive fields like passwords or tokens from a dataset.
Example
jq 'del(.. | .ssn?)' user_dump.jsonjq 'map_values(if . == null then "N/A" else . end)'Normalizes nulls or empty strings across an object.
Example
jq 'map_values(if . == "" then null else . end)' data.jsonjq '[leaf_paths as $path | { "key": $path | join("."), "value": getpath($path) }] | from_entries'Flattens a deeply nested JSON object into a single-level dot-notation map.
Example
jq '...' nested_config.jsondocker inspect container | jq '.[0].NetworkSettings.IPAddress'Extracts networking or metadata information from container runtime output.
Example
kubectl get pod -o json | jq '.items[].metadata.name'kubectl get secret -o json | jq '.data | map_values(@base64d)'Decodes Kubernetes secrets directly from the JSON output.
Example
jq '.data | map_values(@base64d)' k8s_secret.jsongh api repos/:owner/:repo/issues | jq 'map(select(.labels[].name == "bug"))'Filters GitHub API issues by label or state.
Example
curl ... | jq 'map(select(.state == "open"))'jq -s 'map(.timestamp) | max - min' packets.jsonCalculates the time duration or average latency from a capture file.
Example
jq -s 'map(.latency) | add / length' ping.jsonjq 'select(.event_id == 4624 and .logon_type == 10)' winlogs.jsonFilters Windows Event Logs for RDP logins (Type 10) or failures.
Example
jq 'select(.id == 4625)' security.jsonjq 'group_by(.src_ip) | map({ip: .[0].src_ip, count: length}) | sort_by(.count) | reverse'Generates a frequency analysis of source IPs to identify potential attackers.
Example
jq 'group_by(.user) | map({user:.[0].user, count:length})' firewall.jsonjq 'reduce inputs as $item (.; .[$item.id] = $item)'Transforms a stream of objects into a hash map indexed by ID.
Example
jq -n 'reduce inputs as $x ({}; .[$x.name] = $x.value)' data.txtjq 'transpose | map(add)' matrix.jsonTransposes a matrix (array of arrays) or sums columns.
Example
jq 'transpose' arrays.jsonjq '.Statement[] | select(.Effect == "Allow" and .Action == "*")'Audits IAM policies for overly permissive wildcard permissions.
Example
jq '.Statement[] | select(.Resource == "*")' policy.jsonjq --stream 'select(.[0][1] == "id") | .[1]'Parses massive files token-by-token to reduce memory usage.
Example
jq -cn --stream 'fromstream(1|truncate_stream(inputs))' huge.jsonjq -cn --stream 'fromstream(inputs | select(.[0][0] == "users"))'Reconstructs only specific parts of a large JSON file from a stream.
Example
jq --stream 'select(length==2) | .[0] as $p | .[1] as $v | "\($p): \($v)"' large.jsonjq -R -s 'split("\n") | .[1:] | map(split(",")) | map({id: .[0], val: .[1]})'Manually converts raw CSV text into JSON objects (header aware).
Example
jq -R -s '...' data.csvjq -n --argfile a old.json --argfile b new.json '$a == $b'Compares two JSON files for strict equality or diffs object keys.
Example
jq -n --argfile a 1.json --argfile b 2.json '$a - $b'jq -n --argfile a old.json --argfile b new.json '($b - $a)'Outputs the fields present in the second file that are missing or different in the first.
Example
jq -n --argfile a v1.json --argfile b v2.json '($b - $a)'jq '.features[] | select(.properties.population > 1000000)' geo.jsonFilters GeoJSON feature collections based on property data.
Example
jq '.features[].geometry.coordinates' cities.jsonjq 'try .foo catch "fallback"'Catches errors during evaluation and provides a default value.
Example
jq 'map(try .value catch 0)' mixed.jsonjq 'try (.a / .b) catch error("division by zero")'Raises a custom error message to halt processing.
Example
jq 'if .b == 0 then error("zero") else .a/.b end' math.jsonjq '.users[] | select([.roles[] | contains("admin")] | any)'Selects objects where at least one element in a nested array matches a condition.
Example
jq '.items[] | select([.tags[] | startswith("pro")] | any)' data.jsonjq 'select(.key | IN("A", "B", "C"))'Filters based on a value membership in a specific list.
Example
jq 'select(.status | IN("pending", "running"))' jobs.jsonjq 'combinations'Outputs the Cartesian product of the input arrays.
Example
jq '[[1,2], ["a","b"]] | combinations' file.jsonjq 'unique_by(.)'Checks if complex objects are identical by deduplicating them.
Example
jq '[.a, .b] | unique_by(.) | length == 1' compare.jsonjq '.' jq_reference_guide.jsonReads and pretty-prints the file itself to validate its own structure.
Example
jq '.' self.jsonTransfers data with URLs over HTTP, FTP and many other protocols. Indispensable for testing APIs, headers and authentication.
A human-friendly HTTP client with intuitive syntax, JSON support and coloured output — great for exploring APIs.
A pattern-scanning language for column-based text: extract fields, compute totals and reformat output.
Encodes and decodes Base64, the standard way to carry binary data over text channels — common in tokens, config files and shell file-transfer tricks.