JQ for parsing JSON Flashcards

1
Q

Which query to get only the ID informations displayed?

A

.id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which query to get the first name?

A

.name.first

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which query to get the “end”

A

.terms[0].end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What will be the difference in the output between those two queries:

.terms

.terms[]

A

By adding the empty squared bracket in the query, the output will not show them. The output gets simplified that way.

  • .terms –> will show the array square brackets. It’s like asking “show me what that key is containing” - and it will show the resulting infos in an array
  • .terms[] –> it’s like: we already know that it’s an array and we’re entering it to see what’s inside. It’s like asking “show me what’s inside this array”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What will be the output of the following query (using the pipe operator):

.[] | .name

A

“JSON”
“XML”

The pipe operator combines two filters by feeding the output(s) of the one on the left into the input of the one on the right

It basically says, take all the data from this array and gather the values of the “name” key.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly