Advertisement
jms1

Question about jq

May 16th, 2016
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.18 KB | None | 0 0
  1. $ jq --version
  2. jq-1.4
  3. $ cat zout | jq -r -M .
  4. {
  5.   "rbac-service": {
  6.     "service_version": "0.6.38",
  7.     "service_status_version": 1,
  8.     "detail_level": "info",
  9.     "state": "running",
  10.     "status": {
  11.       "db_up": true,
  12.       "activity_up": true
  13.     }
  14.   },
  15.   "activity-service": {
  16.     "service_version": "0.3.6",
  17.     "service_status_version": 1,
  18.     "detail_level": "info",
  19.     "state": "running",
  20.     "status": {
  21.       "db_up": true
  22.     }
  23.   },
  24.   "classifier-service": {
  25.     "service_version": "1.5.15",
  26.     "service_status_version": 1,
  27.     "detail_level": "info",
  28.     "state": "running",
  29.     "status": {
  30.       "environment_sync": true,
  31.       "db_up": true,
  32.       "rbac_up": true,
  33.       "activity_up": true
  34.     }
  35.   }
  36. }
  37.  
  38. Desired output: (need the value of the "state" key from the child dictionaries)
  39.  
  40. {
  41.   "rbac-service": "running",
  42.   "activity-service": "running",
  43.   "classifier-service": "running"
  44. }
  45.  
  46. For future reference, this is the answer I received when I asked about it on Freenode #jq ...
  47.  
  48. $ cat zout | jq -r -M 'with_entries(.value |= .state)'
  49. {
  50.   "activity-service": "running",
  51.   "classifier-service": "running",
  52.   "rbac-service": "running"
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement