-
Documentation task
-
Resolution: Fixed
-
Trivial
-
4.2.3
"zbx_jsonpath_next" function is able to work with arrays and it's possible to specify them in the path, but it's not documented as it should.
Moreover, current documentation for "JSON Path" is not clear an misleads in this regard.
https://www.zabbix.com/documentation/4.2/manual/config/items/item#item_value_preprocessing
Working examples (both) for zabbix:
$.sensors["2"].capabilities["inputs"][0].events $.sensors.2.capabilities["inputs"][0].events
where ["2"] or .2. is an object key name, and [0] is an order of object in array.
Working examples from command line:
curl http://localhost/below.json 2>/dev/null | jsonpath '$.sensors."2".capabilities.inputs[0].events' curl http://localhost/below.json 2>/dev/null | jq '.sensors."2".capabilities.inputs[0].events'
JSON used for tests above (real device, data a bit shortened):
{ "sensors": { "2": { "uniqueid": "00:17:88:01:04:ef:05:5f-02-fc00", "capabilities": { "certified": true, "inputs": [ { "repeatintervals": [ 800 ], "events": [ { "buttonevent": 1000, "eventtype": "initial_press" }, { "buttonevent": 1001, "eventtype": "repeat" } ] }, { "repeatintervals": [ 800 ], "events": [ { "buttonevent": 2000, "eventtype": "initial_press" }, { "buttonevent": 2001, "eventtype": "repeat" } ] } ] } }, "3": { "uniqueid": "WA0001" } } }
Suggested changes for the doc page:
All examples, containing [0] should explain that it's an array index, not object key name.
It will be better to not use such [0] in first example. It should be short "$.document.item.value".
And add one more example:
If object name is a digit and bracket notation is used, it must be quoted. If dot notation is used, it must be specified as just object name:
$["8"].items[2].value or $.8.items[2].value will extract 30 from {"8":{"items":[{"value": 10},{"value": 20},{"value": 30}]}}