Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, it is possible to retrieve objects as a list in jq and access them by index using the built-in keys function to get the keys of the object and then using the .[index] operator to access the values associated with those keys. Here's an example:

Suppose you have the following JSON object:

{
  "foo": "bar",
  "baz": 42,
  "qux": true
}

You can retrieve the values of this object as a list using the following jq query:

$ jq '[.[]]' example.json

This will output the values of the object as a list:

[
  "bar",
  42,
  true
]

You can then access individual values in this list by index using the .[index] operator. For example, to access the second element in the list (which has an index of 1), you can use the following jq query:

$ jq '[.[]][1]' example.json

This will output:

42