Dariusz Mydlarz
Sep 3 · 1 min read

jq can be used in order to efficiently count JSON array length from command line.


Given JSON file out.json like this.

{
"meta": {},
"data": [
{
"id": 1
},
{
"id": 2
}
]
}

In order to count data length, you can use jq.

$ cat out.json | jq '.data | length'
19226

For 57 MB file it takes 1.97 seconds.

darek1024

Microblog About Programming. For More Head to sztukakodu.pl

Dariusz Mydlarz

Written by

Software Engineer keen on delivering best value for the business

darek1024

darek1024

Microblog About Programming. For More Head to sztukakodu.pl

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade