Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Prints id of all passed tasks in Json file using bash

I have a Json file like below,

{
  "tasks": [
    {
      "id": "nightly_1652299200",
      "repo": "tx/tx5",
      "branch": "dev",
      "type": "HealthCheck",
      "started_on": "2022-05-11 23:00:00 +0300 EEST",
      "state": "Running",
      "top_sha": "10143120c12cd506fca5a466a7c6b27e7cb35b18",
      "tested_shas": null,
      "self_url": "tx/tx5/10143120c12cd506fca5a466a7c6b27e7cb35b18",
      "is_public": true
    },
    {
      "id": "1652298808",
      "repo": "tx/tx3d",
      "branch": "6.3",
      "type": "Integration",
      "started_on": "2022-05-11 22:53:28 +0300 EEST",
      "state": "Passed",
      "top_sha": "40ca8db14a8ddd082270a81e895bf01048949ec4",
      "tested_shas": null,
      "self_url": "tx/tx3d/40ca8db14a8ddd082270a81e895bf01048949ec4",
      "is_public": true
    },
    {
      "id": "1652298252",
      "repo": "tx/qtmultimedia",
      "branch": "dev",
      "type": "Integration",
      "started_on": "2022-05-11 22:44:12 +0300 EEST",
      "state": "Failed",
      "top_sha": "d7dd593b6395a33862742a04a23d88b970f7b914",
      "tested_shas": null,
      "self_url": "qt/qtmultimedia/d7dd593b6395a33862742a04a23d88b970f7b914",
      "is_public": true
    }
}

I need to find the ID of each and every Passed tasks ("state": "Passed") using a bash script. what will be the best approach for this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Using jq:

jq -r '.tasks | .[] | select (.state == "Passed") | .id' file.json
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading