Skip to main content
Panther Knowledge Base

How do I use deep_get() to get a value from a nested array?

QUESTION

How do I use the deep_get() helper function to return a value from a nested array?

For example, in the below event, I would like to get the value of "streetNumber"—in this case, 123.

{"country": {
    "states": {
			"cities": [
				{
					"streetNumber": 123,
					"city": "Oakland"
				}
			]
		}
    }
}

ANSWER

The deep_get() helper function does not currently support accessing a nested array's value. One workaround, however, is to store the deep_get() reference in a variable up to the nested array, then access into the array.

cities_list = deep_get(event, "country", "states", "cities")
cities_list[0]["streetNumber"]