gVal expression to evaluate the length of JSON Array

Hi,

We have a synthetics lightweight HTTP Ping monitor, that returns a JSON.

The requirement is to check the length of an array in JSON response.

I used the response from the following URL to test it

https://status.sendgrid.com/api/v2/components.json

Following are the different expressions that I tried and none of them seem to work


* length($.components) == 16

* len($.components) == 16

* $.components.length == 16

following the JSON Used

{
  "page": {
    "id": "3tgl2vf85cht",
    "name": "SendGrid",
    "url": "https://status.sendgrid.com",
    "time_zone": "America/Los_Angeles",
    "updated_at": "2025-10-28T10:11:04.073-07:00"
  },
  "components": [
    {
      "id": "06b486vkpf0h",
      "name": "Mail Sending",
      "status": "operational",
      "created_at": "2015-11-18T06:18:04.342-08:00",
      "updated_at": "2018-05-05T00:04:05.478-07:00",
      "position": 1,
      "description": null,
      "showcase": false,
      "start_date": null,
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": true,
      "only_show_if_degraded": false,
      "components": [
        "s0rtr2pvxgzq",
        "nqgmzl9pxtd5",
        "q6bv40cywctx"
      ]
    },
    {
      "id": "0srpdt598t37",
      "name": "Marketing Campaigns",
      "status": "operational",
      "created_at": "2015-11-18T06:21:16.020-08:00",
      "updated_at": "2025-10-20T16:01:26.050-07:00",
      "position": 1,
      "description": "Website, and API access to Marketing Campaigns features.",
      "showcase": false,
      "start_date": null,
      "group_id": "1qrzrn1qxjfx",
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "p9560qrfxy9k",
      "name": "Event Webhook",
      "status": "operational",
      "created_at": "2015-11-18T06:23:17.600-08:00",
      "updated_at": "2025-07-17T09:02:55.040-07:00",
      "position": 1,
      "description": "Real-time POST of event data to a provided URL.",
      "showcase": false,
      "start_date": null,
      "group_id": "dcvwpwy7361c",
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "s0rtr2pvxgzq",
      "name": "API v3",
      "status": "operational",
      "created_at": "2016-05-10T12:44:00.908-07:00",
      "updated_at": "2025-10-16T10:04:51.862-07:00",
      "position": 1,
      "description": "The flow of mail generated by mail.send API requests",
      "showcase": false,
      "start_date": null,
      "group_id": "06b486vkpf0h",
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "nqgmzl9pxtd5",
      "name": "SMTP",
      "status": "operational",
      "created_at": "2015-11-18T06:18:39.550-08:00",
      "updated_at": "2025-04-25T06:42:18.373-07:00",
      "position": 2,
      "description": "Mail sent with direct integrations to smtp.sendgrid.net.",
      "showcase": false,
      "start_date": null,
      "group_id": "06b486vkpf0h",
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "1qrzrn1qxjfx",
      "name": "Marketing Campaigns",
      "status": "operational",
      "created_at": "2015-11-18T06:21:16.010-08:00",
      "updated_at": "2015-12-06T21:30:46.901-08:00",
      "position": 2,
      "description": null,
      "showcase": false,
      "start_date": null,
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": true,
      "only_show_if_degraded": false,
      "components": [
        "0srpdt598t37"
      ]
    },
    {
      "id": "9mk6xltks0dj",
      "name": "Parse API",
      "status": "operational",
      "created_at": "2015-11-18T06:24:07.424-08:00",
      "updated_at": "2025-08-15T11:09:38.769-07:00",
      "position": 2,
      "description": "Inbound mail that is parsed out and POSTed to a provided URL.",
      "showcase": false,
      "start_date": null,
      "group_id": "dcvwpwy7361c",
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "q6bv40cywctx",
      "name": "API v2",
      "status": "operational",
      "created_at": "2015-11-18T06:18:04.353-08:00",
      "updated_at": "2025-10-16T10:04:51.886-07:00",
      "position": 3,
      "description": "The flow of mail generated by mail.send API requests.",
      "showcase": false,
      "start_date": null,
      "group_id": "06b486vkpf0h",
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "dcvwpwy7361c",
      "name": "Webhooks",
      "status": "operational",
      "created_at": "2015-11-18T06:23:17.591-08:00",
      "updated_at": "2015-11-18T06:26:08.590-08:00",
      "position": 3,
      "description": null,
      "showcase": false,
      "start_date": null,
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": true,
      "only_show_if_degraded": false,
      "components": [
        "p9560qrfxy9k",
        "9mk6xltks0dj"
      ]
    },
    {
      "id": "vgl8t6wflyjt",
      "name": "API",
      "status": "operational",
      "created_at": "2015-11-18T06:25:16.300-08:00",
      "updated_at": "2025-09-30T15:54:26.097-07:00",
      "position": 4,
      "description": "General API functionality not including mail.send calls",
      "showcase": false,
      "start_date": null,
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "4kpfnh9zn3cq",
      "name": "Website",
      "status": "operational",
      "created_at": "2015-11-18T06:19:03.286-08:00",
      "updated_at": "2025-10-16T10:04:51.907-07:00",
      "position": 5,
      "description": "Availability of SendGrid.com",
      "showcase": false,
      "start_date": null,
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "ry6z0hmq55qg",
      "name": "Statistics",
      "status": "operational",
      "created_at": "2021-03-24T12:00:44.175-07:00",
      "updated_at": "2025-10-22T14:56:36.468-07:00",
      "position": 6,
      "description": "Availability of Global and Category stats",
      "showcase": false,
      "start_date": "2021-03-24",
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "mdt4hw660r2x",
      "name": "Email Activity",
      "status": "operational",
      "created_at": "2018-05-01T11:04:58.442-07:00",
      "updated_at": "2025-10-07T14:39:36.681-07:00",
      "position": 7,
      "description": "Email Activity Feed event data and functionality",
      "showcase": false,
      "start_date": null,
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "ylw5fnzv1r15",
      "name": "Partners",
      "status": "operational",
      "created_at": "2021-02-24T09:35:17.332-08:00",
      "updated_at": "2025-05-13T20:23:22.238-07:00",
      "position": 8,
      "description": "Partner reseller services and integrations",
      "showcase": false,
      "start_date": "2021-02-24",
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "9m1d2fwwqpkt",
      "name": "Billing",
      "status": "operational",
      "created_at": "2021-03-24T12:14:30.621-07:00",
      "updated_at": "2025-09-16T10:50:47.726-07:00",
      "position": 9,
      "description": "Billing and Invoicing services",
      "showcase": false,
      "start_date": "2021-03-24",
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    },
    {
      "id": "2b4vzs4vjl4z",
      "name": "Legacy Marketing Campaigns",
      "status": "operational",
      "created_at": "2024-07-31T16:17:52.016-07:00",
      "updated_at": "2025-08-05T14:52:45.237-07:00",
      "position": 10,
      "description": null,
      "showcase": false,
      "start_date": "2024-07-31",
      "group_id": null,
      "page_id": "3tgl2vf85cht",
      "group": false,
      "only_show_if_degraded": false
    }
  ]
}

Appreciate any help.

Thanks

Hello @Chow

I see we can use below expression :

Tried for :

https://status.sendgrid.com/api/v2/status.json

{
  "page": {
    "id": "3tgl2vf85cht",
    "name": "SendGrid",
    "url": "https://status.sendgrid.com",
    "time_zone": "America/Los_Angeles",
    "updated_at": "2025-10-28T16:30:58.410-07:00"
  },
  "status": {
    "indicator": "none",
    "description": "All Systems Operational"
  }
}


If we use below filter it works => 

Response body contains :
"indicator\":\"none"

If we change to below it will fail => only positive pattern mismatch
"indicator\":\"green"


For Components we can use below :

"components":\s*\[([^\]]*,){15}[^\]]*\]

Thanks!!

Hi @Tortoise

Thank you for the response. But what I was trying to validate is the length of the Array, The size varies depending on the URL and we have a different check in different monitors.

Thank you

Hello @Chow

Yes for length as i shared we can use below :

For Components we can use below :

"components":\s*\[([^\]]*,){15}[^\]]*\]

Could you please confirm if you are trying to find the length in components array or compare the JSON components output array == 16 or not ?

As for above if you use 16 (0-16) instead of 15, count become 17 , in this it fails because the URL you shared has 16 length for component array (0-15) . For 15 it passes (component array count 16) & synthetic is Green.

Thanks!!