Senator Ernst is new to Congress (and the first woman to represent Iowa in Congress), so her JSON-object representation is brief enough for now to read on one page. The object includes 4 nested objects, under the attributes, id, name, bio, terms.

Use jq to view each of these attributes separately, by prepending a dot to the desired attribute:

Because Senator Ernst has so far served only one term, there is only one object in the .terms array. However, trying to access the start attribute, using just the dot notation for attributes, will result in an error:

Accessing objects in an array

The individual objects in an array are indexed by number, starting from zero. In other words, if we want to get the start attribute for Senator Ernst's 1st term, we tell jq that we want the 0th element, and we use the square bracket notation when accessing an array, in this case, the terms array.

In the result below, take particular note of the lack of square brackets: by specifying a specific element in terms, we get a single object in return:

Try accessing the 1st element in terms; if Senator Ernst has only served one term, and that term is accessible via the 0th element, think to yourself what the 1st element in the terms array will contain:

user@host:~$ cat ernst.json | jq '.terms[1] .start'
null

Rep. Nancy Pelosi as a JSON object

The terms array for Sen. Ernst is still an array, even with one object. But let's see how an array of multiple objects works: we can use Rep. Nancy Pelosi as an example, as she's been in Congress for multiple terms:

With the JSON files for Rep. Pelosi and Sen. Ernst, we were dealing with single Congressmember objects. This legislators.json contains an array of those Congressmember objects. So this query to find the name attribute will fail:

So we have to use the array selector (the []) to access individual objects. To find the name object of the first Congressmember object (again, remember that elements in the array are numbered starting with 0):

The jq tool outputs formatted text that looks nice, but often we just need it in a raw form that can be filtered into our other command-line tools – notice how the --raw-output option removes the quotation marks from the output: