jq: The Command-line JSON processor

Usage

Beautify Json

When a curl or other application returns a minified JSON, beautifying it makes it a lot more easy to read.

curl <url> | jq '.'

   1 # Example:
   2 
   3 > curl -s http://dummy.restapiexample.com/api/v1/employees
   4 {"status":"success","data":[{"id":"1","employee_name":"Tiger Nixon","employee_salary":"320800","employee_age":"61","profile_image":""},{"id":"2","employee_name":"Garrett Winters","employee_salary":"170750","employee_age":"63","profile_image":""},....
   5 
   6 > curl -s http://dummy.restapiexample.com/api/v1/employees | jq '.'
   7 {
   8   "status": "success",
   9   "data": [
  10     {
  11       "id": "1",
  12       "employee_name": "Tiger Nixon",
  13       "employee_salary": "320800",
  14       "employee_age": "61",
  15       "profile_image": ""
  16     },
  17     {
  18       "id": "2",
  19       "employee_name": "Garrett Winters",
  20       "employee_salary": "170750",
  21       "employee_age": "63",
  22       "profile_image": ""
  23     },...

Limiting depth

With large unknown datasets, it might be interesting to only see the first few 'levels' of the response The amount of []? determains how many levels wil be shown

curl <url> | jq 'del(.[]?[]?[]?[]?)'

   1 # Example:
   2 
   3 > curl -s http://dummy.restapiexample.com/api/v1/employees | jq 'del(.[]?[]?)'
   4 {
   5   "status": "success",
   6   "data": []
   7 }

Howto/jq (last edited 2021-01-23 19:36:10 by Burathar)