4

I am trying to get multiple values from a json object.

{
    "nextToken": "9i2x1mbCpfo5hQ",
    "jobSummaryList": [
        {
            "jobName": "012210",
            "jobId": "0196f81cae73"
        }
    ]
}

I want nextToken's value and jobName in one jq command.

6
  • 2
    Please share an example of how valid output data should look like. Since jobName is part of an array there could be multiple solutions. Also please share what you have already tried. Commented Jun 5, 2019 at 9:25
  • jq .nextToken, .jobSummaryList[].jobName note that the json-line inserted above is incorrect - or incomplete you need to close the brackets. Commented Jun 5, 2019 at 9:37
  • I have tried following command :jq '.jobSummaryList[]|select(.jobName|contains("23244"))' Commented Jun 6, 2019 at 10:11
  • it looks like this:{ "nextToken": "9i2x1mbCpfo5hQ", "jobSummaryList": [ { "jobName": "012210", "jobId": "0196f81cae73" }{ "jobName": "123457", "jobId": "jhdktjjk" } ] } Commented Jun 6, 2019 at 10:16
  • i want to extract either nextToken if present or jobName and JobId Commented Jun 6, 2019 at 10:18

1 Answer 1

3

https://stedolan.github.io/jq/manual/

jq '.nextToken, .jobSummaryList[].jobName' file
Sign up to request clarification or add additional context in comments.

1 Comment

aws batch list-jobs --job-queue prd-worker-job-queue --job-status SUCCEEDED --region ap-northeast| jq '.nextToken, .jobSummaryList[].jobName[]|select(.jobSummaryList[].jobName=="305200210")'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.