We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

jq Basics

Once installed, you can use jq to parse and manipulate JSON data. Here's a simple example to get you started. Suppose you have a JSON file named user.json:

{
  "name": "John",
  "age": 30,
  "city": "New York"
}

To extract the name field, you would use:

jq '.name' user.json
# "John"

jq with cURL

jq is frequently used with cURL to parse JSON responses directly from HTTP requests. For example, to fetch JSON data from an API and extract a field we can use the object identifier index:

curl https://jsonplaceholder.typicode.com/users/1 | jq .username
# "Bret"

To get a field from each element in an array you can use the array/object value iterator .[], which can in turn be combined with the identifier index:

curl https://jsonplaceholder.typicode.com/users | jq '.[].username'
# "Bret"
# "Antonette"
# "Samantha"
# "Karianne"
# "Kamren"
# "Leopoldo_Corkery"
# "Elwyn.Skiles"
# "Maxime_Nienow"
# "Delphine"
# "Moriah.Stanton"

Multiple Fields

curl https://jsonplaceholder.typicode.com/users/1 | jq '.name, .email'
# "Leanne Graham"
# "[email protected]"

jq is extremely powerful. We won't cover every feature in this course, but it's a tool you should know about for the future.

Assignment

https://api.boot.dev/v1/courses_rest_api/learn-http/issues

Run and submit the CLI tests.