'Read json values using sed or awk. I am not allowed to use jq

For the following json data, I need to retrieve the value of the status. I tried to look for examples online and adopt the same, but couldn't do it successfully as this json has arrays. Can you please help me retrieving the "status" in the following json?

This is how the jq version looks echo $JSON | jq -r .data.affected_items[].status I need the same using

{
  "data": {
    "affected_items": [
      {
        "os": {
          "arch": "x86_64",
          "major": "2",
          "name": "Amazon Linux",
          "platform": "amzn",
          "uname": "Linux |ip-10-179-120-6.vpc.internal |4.14.256-197.484.amzn2.x86_64 |#1 SMP Tue Nov 30 00:17:50 UTC 2021 |x86_64",
          "version": "2"
        },
        "manager": "wazuh-manager-worker-0",
        "dateAdd": "2022-02-24T08:42:52Z",
        "lastKeepAlive": "2022-03-08T04:33:44Z",
        "group": [
          "default"
        ],
        "name": "ec2_us-west-2_279976188247_i-030ccd7d70b84f0ee",
        "ip": "10.179.120.6",
        "configSum": "ab73af41699f13fdd81903b5f23d8d00",
        "node_name": "wazuh-manager-worker-0",
        "status": "active",
        "version": "Wazuh v4.1.5",
        "mergedSum": "56dfa0edef630b932284df2f81bf4a1c",
        "id": "006",
        "registerIP": "any"
      }
    ],
    "total_affected_items": 1,
    "total_failed_items": 0,
    "failed_items": []
  },
  "message": "All selected agents information was returned",
  "error": 0
}


Solution 1:[1]

If this isn't all you need:

$ sed -n 's/.*"status": \("[^"]*"\).*/\1/p' file
"active"

then edit your question to contain a better explanation of your requirements and more truly representative sample input/output that the above doesn't work for.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ed Morton