Detect empty array


(Thor) #1

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
      	}
      ]

(Guy Boertje) #2
if [serviceContexts] and [serviceContexts][0] {
  # array has at least one element
} else {
  # array has no elements
}

(Thor) #3

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

Thanks