Just like how you are piping json data from echo command, from a file, you can even extract the curl command output using jq tool.
Example 1: Get name of github project.
$curl https://api.github.com/repos/harikrishna553/springboot | jq '.name'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5601  100  5601    0     0   6182      0 --:--:-- --:--:-- --:--:--  6175
"springboot"
Example 2: get url of github project.
$curl https://api.github.com/repos/harikrishna553/springboot | jq '.html_url'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5601  100  5601    0     0   6350      0 --:--:-- --:--:-- --:--:--  6343
"https://github.com/harikrishna553/springboot"
Example 3: Get name, url, size and full name of the github project.
$curl https://api.github.com/repos/harikrishna553/springboot | jq '.name, .html_url, .size, .full_name'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5601  100  5601    0     0   6237      0 --:--:-- --:--:-- --:--:--  6230
"springboot"
"https://github.com/harikrishna553/springboot"
520
"harikrishna553/springboot"
 
 
No comments:
Post a Comment