Step: Array Index: .[2]
Array Index: .[2]
Just like in most programming languages you can get element from array using operator []
If top level field is an array you can do .[1]
, if array is nested somewhere then you need to use nested fields first .car.options[1]
Arrays are zero-based, so .[2]
returns the third element.
Negative indices are allowed, with -1
referring to the last element, -2
referring to the next to last element, and so on.
Now see if you can fetch first hobby of a person represented by a JSON below.
Input:
Expected: