Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

Get a specific key and value from JSON

$
0
0

I need something very simple. Sorry I am not familiar with jq and a top novice.

{"pets": [    {"name": "Purrsloud","species": "Cat","favFoods": ["wet food","dry food","<strong>any</strong> food"      ],"birthYear": "feat-2016"    },    {"name": "Barksalot","species": "Dog","birthYear": "feat-2008"    },    {"name": "Meowsalot","species": "Cat","favFoods": ["tuna","catnip","celery"      ],"birthYear": "feat-2012"    }  ]}

I would like to test 2 jq commands so 2 outputs to:

  • 1st test: Fetch only the value Meowsalot
.pets[].name.Meowsalot

I am not sure what I am doing wrong above. The output error on jqplay.org:

Error: jq: error (at /dev/stdin:28): Cannot index string with string "Meowsalot"
  • 2nd test: Fetch only the highest birthYear value which should be feat-2016. By doing some research I saw that the max_by function could do it but really unsure how to use it.

Thanks team


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>