0

I have a URL which returns a list of tasks for my applicaiton.

Request:   /marathon/v2/apps/myapplication/tasks/


Response:  {"tasks":[{"ipAddresses":[{"ipAddress":"172.17.0.3","protocol":"IPv4"}],"stagedAt":"2018-03-19T15:38:59.486Z","state":"TASK_RUNNING","ports":[22660],"startedAt":"2018-03-19T15:39:05.571Z","version":"2018-03-19T15:38:59.157Z","id":"myapplication.a47c2cd2-2b8b-11e8-a2bb-0e25310fd094","appId":"/myapplication","slaveId":"d0207878-76c3-4ce5-8d1a-f2cab319728c-S2","host":"10.134.52.126"}]}

Tasks field in response is an array. How to get first item from this array?

yu.pitomets
  • 1,660
  • 2
  • 17
  • 44

1 Answers1

0

You can use 'jq' utility to parse json inputs. In your case, it will be :

# To get First task details
cat response.json | jq '.tasks[0]'

# To get First task id
cat response.json | jq '.tasks[0].id'

# To get id of all tasks
cat response.json | jq '.tasks[] | .id'
Parvez Kazi
  • 660
  • 5
  • 13