Today I learnt about jq - "a lightweight and flexible command-line JSON processor".
One of the use cases is pretty-printing JSON response on the terminal.
It essentially makes JSON data more readable on your terminal. If you work with a lot of JSON data on your terminal, you need to install jq
.
Before jq
:
$ curl localhost:3001/api/food?q=hash+browns
[{"description":"Fast foods, potatoes, hash browns, rnd pieces or patty","kcal":272.0,"fat_g":16.03,"carbohydrate_g":28.88,"protein_g":2.58},{"description":"Chick-fil-a, hash browns","kcal":301.0,"fat_g":17.36,"carbohydrate_g":30.51,"protein_g":3.0},{"description":"Denny's, hash browns","kcal":197.0,"fat_g":8.75,"carbohydrate_g":26.59,"protein_g":2.49},{"description":"Restaurant, family style, hash browns","kcal":197.0,"fat_g":8.75,"carbohydrate_g":26.59,"protein_g":2.49},{"description":"Fast foods, potatoes, hash browns, rnd pieces or patty","kcal":272.0,"fat_g":16.03,"carbohydrate_g":28.88,"protein_g":2.58},{"description":"Chick-fil-a, hash browns","kcal":301.0,"fat_g":17.36,"carbohydrate_g":30.51,"protein_g":3.0},{"description":"Denny's, hash browns","kcal":197.0,"fat_g":8.75,"carbohydrate_g":26.59,"protein_g":2.49},{"description":"Restaurant, family style, hash browns","kcal":197.0,"fat_g":8.75,"carbohydrate_g":26.59,"protein_g":2.49}]
After jq
:
$ curl localhost:3001/api/food?q=hash+browns | jq '.'
[
{
"description": "Fast foods, potatoes, hash browns, rnd pieces or patty",
"kcal": 272,
"fat_g": 16.03,
"carbohydrate_g": 28.88,
"protein_g": 2.58
},
{
"description": "Chick-fil-a, hash browns",
"kcal": 301,
"fat_g": 17.36,
"carbohydrate_g": 30.51,
"protein_g": 3
},
{
"description": "Denny's, hash browns",
"kcal": 197,
"fat_g": 8.75,
"carbohydrate_g": 26.59,
"protein_g": 2.49
},
{
"description": "Restaurant, family style, hash browns",
"kcal": 197,
"fat_g": 8.75,
"carbohydrate_g": 26.59,
"protein_g": 2.49
},
{
"description": "Fast foods, potatoes, hash browns, rnd pieces or patty",
"kcal": 272,
"fat_g": 16.03,
"carbohydrate_g": 28.88,
"protein_g": 2.58
},
{
"description": "Chick-fil-a, hash browns",
"kcal": 301,
"fat_g": 17.36,
"carbohydrate_g": 30.51,
"protein_g": 3
},
{
"description": "Denny's, hash browns",
"kcal": 197,
"fat_g": 8.75,
"carbohydrate_g": 26.59,
"protein_g": 2.49
},
{
"description": "Restaurant, family style, hash browns",
"kcal": 197,
"fat_g": 8.75,
"carbohydrate_g": 26.59,
"protein_g": 2.49
}
]
To uncover more use cases for jq
, check out the official tutorial