Created
April 2, 2018 20:18
-
-
Save mtho11/0924d2d16e228475a0332d21acab1dff to your computer and use it in GitHub Desktop.
jq using star wars api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Curl command used to display raw API data: | |
| curl -s http://swapi.co/api/people/ | |
| Simple jq filter to pretty print JSON response: | |
| curl -s http://swapi.co/api/people/ | jq '.' | |
| Command to display only the results array: | |
| curl -s http://swapi.co/api/people/ | jq '.results' | |
| Command to display only the first item from the results array: | |
| curl -s http://swapi.co/api/people/ | jq '.results[0]' | |
| Command to display name, birth year and gender of the first item in the results array: | |
| curl http://swapi.co/api/people/ | jq '.results[0] | { name: .name, birthday: .birth_year, gender: .gender }' | |
| Command to display name, birth year and gender for all items in the results array: | |
| curl http://swapi.co/api/people/ | jq '.results[] | { name: .name, birthday: .birth_year, gender: .gender }' | |
| Command to display array objects within the result set: | |
| curl http://swapi.co/api/people/ | jq '.results[0] | { name: .name, vehicles: .vehicles }' | |
| Command to convert the height attribute to a number and multiply by 0.39370 to convert to inches: | |
| curl -s http://swapi.co/api/people/ | jq '.results[0].height | tonumber? * 0.39370' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment