Sort by numeric field

Get 5 most recent events sorted by timestamp descending

jq 'sort_by(.timestamp) | reverse | .[0:5]' events.json

tool
jq17 commands
tags
jq

More jq commands

  • jq -r '.[] | [.id, .name, .status] | @csv' data.json

    Output selected fields as comma-separated values

  • jq '[.[] | . + {"env": "prod"}]' items.json

    Inject a new key-value pair into every array element

  • jq 'walk(if type == "string" then ascii_downcase else . end)' data.json

    Recursively lowercase all string values in a JSON document

  • cat data.json | jq '.'

    Format and colorize a JSON file

  • cat data.json | jq '.items[] | select(.status == "Running")'

    Select objects where a field equals a value

all 17 jq commands