jq for JSON

brew install jq
// Using this JSON file:
// https://raw.githubusercontent.com/algolia/datasets/master/movies/actors.json
// Get the 10th item in an array
cat actors.json | jq '.[10]'
// {
// "name": "Dwayne Johnson",
// "rating": 1568,
// "image_path": "/akweMz59qsSoPUJYe7QpjAc2rQp.jpg",
// "alternative_name": "The Rock",
// "objectID": "551486400"
// }
// Get a property from the 10th item in array
// > "Dwayne Johnson"
// Get multiple items
jq '.[10:12]'
// Get items up to the 12th position
jq '.[:12]'
// Get items after the 12th position
jq '.[12:]'
// Get an array of properties from all objects
jq '.[].name'
// > ["William Shatner", "Will Ferrell", ...]
// Create an object with only properties I want
jq '{ name: .[].name, rating: .[].rating}'
// Built in functions!
jq 'sort'
jq 'length'
jq 'reverse'

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store