Count JSON objects in a file using jq

Simply run:

cat input_file.json | jq 'length'

For example:

{
"entity_id_01": {
"field_a": "value_a",
"field_b": "value_b",
"field_c": "This is a generic feedback message"
},
"entity_id_02": {
"field_a": "value_a",
"field_b": "value_b",
"field_c": "This is a generic feedback message"
}
}

Will return 2!

That’s it, Enjoy!

Sources:

Unknown's avatar

About Ahmed Tawfik

Cybersecurity Professional, Systems Engineer, OSS & Linux Geek
This entry was posted in Linux and tagged , . Bookmark the permalink.

Leave a comment