Cheatsheet Pages / jq Cheatsheet

How to count things in JSON with jq — length

How many users are in the array? How long is that string? How many keys does the object have?

Every filter was executed against the cheatsheet's sample config.json with jq 1.7 before publishing; the sample file sits at the bottom of the cheatsheet so you can reproduce every output.

jq '.users | length' config.json   # -> 3
jq '.name | length' config.json    # -> 10  (characters in "api-server")
jq Cheatsheet one-page card — 30 filters that actually work
The full one-page card — jq Cheatsheet. Get the complete cheatsheet on GitHub