jq cheatsheet

curl https://reqres.in/api/users | jq .
curl https://reqres.in/api/users | jq .page
1
curl 'https://reqres.in/api/users' | jq .data
[
{
"id": 1,
"email": "george.bluth@reqres.in",
"first_name": "George",
"last_name": "Bluth",
"avatar": "https://reqres.in/img/faces/1-image.jpg"
},
{
"id": 2,
"email": "janet.weaver@reqres.in",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-image.jpg"
},
{
"id": 3,
"email": "emma.wong@reqres.in",
"first_name": "Emma",
"last_name": "Wong",
"avatar": "https://reqres.in/img/faces/3-image.jpg"
},
{
"id": 4,
"email": "eve.holt@reqres.in",
"first_name": "Eve",
"last_name": "Holt",
"avatar": "https://reqres.in/img/faces/4-image.jpg"
},
{
"id": 5,
"email": "charles.morris@reqres.in",
"first_name": "Charles",
"last_name": "Morris",
"avatar": "https://reqres.in/img/faces/5-image.jpg"
},
{
"id": 6,
"email": "tracey.ramos@reqres.in",
"first_name": "Tracey",
"last_name": "Ramos",
"avatar": "https://reqres.in/img/faces/6-image.jpg"
}
]
curl 'https://reqres.in/api/users' | jq '.data[] | {first_name,last_name}'
{
"first_name": "George",
"last_name": "Bluth"
}
{
"first_name": "Janet",
"last_name": "Weaver"
}
{
"first_name": "Emma",
"last_name": "Wong"
}
{
"first_name": "Eve",
"last_name": "Holt"
}
{
"first_name": "Charles",
"last_name": "Morris"
}
{
"first_name": "Tracey",
"last_name": "Ramos"
}
curl 'https://reqres.in/api/users' | jq '.data[].first_name'
"George"
"Janet"
"Emma"
"Eve"
"Charles"
"Tracey"
curl 'https://reqres.in/api/users' | jq '.data[] | {first_name,last_name} | join(" ")'
"George Bluth"
"Janet Weaver"
"Emma Wong"
"Eve Holt"
"Charles Morris"
"Tracey Ramos"
curl 'https://reqres.in/api/users' | jq '.data[] | select(.first_name == "Eve")'
{
"id": 4,
"email": "eve.holt@reqres.in",
"first_name": "Eve",
"last_name": "Holt",
"avatar": "https://reqres.in/img/faces/4-image.jpg"
}
curl 'https://reqres.in/api/users' | jq '.data[] | select(.first_name == "Eve") | {email}'
{
"email": "eve.holt@reqres.in"
}
curl 'https://reqres.in/api/users' | jq keys
[
"data",
"page",
"per_page",
"support",
"total",
"total_pages"
]
curl 'https://reqres.in/api/users' | jq '.data[1:3]'
[
{
"id": 2,
"email": "janet.weaver@reqres.in",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-image.jpg"
},
{
"id": 3,
"email": "emma.wong@reqres.in",
"first_name": "Emma",
"last_name": "Wong",
"avatar": "https://reqres.in/img/faces/3-image.jpg"
}
]
curl 'https://reqres.in/api/users' | jq '.data | sort_by(.first_name)'
[
{
"id": 5,
"email": "charles.morris@reqres.in",
"first_name": "Charles",
"last_name": "Morris",
"avatar": "https://reqres.in/img/faces/5-image.jpg"
},
{
"id": 3,
"email": "emma.wong@reqres.in",
"first_name": "Emma",
"last_name": "Wong",
"avatar": "https://reqres.in/img/faces/3-image.jpg"
},
{
"id": 4,
"email": "eve.holt@reqres.in",
"first_name": "Eve",
"last_name": "Holt",
"avatar": "https://reqres.in/img/faces/4-image.jpg"
},
{
"id": 1,
"email": "george.bluth@reqres.in",
"first_name": "George",
"last_name": "Bluth",
"avatar": "https://reqres.in/img/faces/1-image.jpg"
},
{
"id": 2,
"email": "janet.weaver@reqres.in",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-image.jpg"
},
{
"id": 6,
"email": "tracey.ramos@reqres.in",
"first_name": "Tracey",
"last_name": "Ramos",
"avatar": "https://reqres.in/img/faces/6-image.jpg"
}
]
curl 'https://reqres.in/api/users' | jq '.data | length'
6

--

--

--

Site Reliability Developer @ Oracle Cloud Infrastructure

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Spring Boot File Download Using Ajax Example | Code Factory

Ionic 4 (Angular)

Javascript ES6: Tips and Tricks Part-2

JavaScript Use Math Method.

Two way data binding for FormBuilder group controls & read disabled control values with help of…

Why JavaScript Call Stack Comes into picture?

Getting Started with NodeJS

Spiral Matrix — Javascript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yugal Arora

Yugal Arora

Site Reliability Developer @ Oracle Cloud Infrastructure

More from Medium

How to create LVM(Logical Volume Manager) in Linux

What I do after Installing Linux

Process Manager-{systemd}

Stupid Bash Tricks: Pretty Path