Extract A List Of Values
jq
can be used to extract a list of values from an array in a JSON file.
Consider the following JSON:
First, you need to specify the selector path to the list. One it's own that will grab the list.
Then you need to use brackets to interact with the list. .items[0]
and .items[1]
would grab the first and second item in the list, respectively. Leaving the brackets empty (.items[]
) tells jq
that you want to interact with each item in the list.
Then tack on a selector for what you want out of each item.
This grabs the name from each of the objects within the items array. The results are printed to stdout.
Last updated
Was this helpful?