Detect empty array

Hi,

how could I detect when an array in a json is empty with logstash ?

example:

  • EMPTY

      "serviceContexts": [
    	]
    
  • FULL:

    "serviceContexts": [{
      		"service": "JIRA",
      		"monitor": true,
      		"client": null,
      		"org": null,
      		"app": null,
      		"method": "KeyGet",
      		"status": "failure",
      		"duration": 1
      	}
      ]
1 Like
if [serviceContexts] and [serviceContexts][0] {
  # array has at least one element
} else {
  # array has no elements
}
2 Likes

Yes this is what I come up with. Wasn't sure if that was the best way to do it.

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.