Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-16234

clarify how to reference object in arrays for "JSON Path" preprocessing step

XMLWordPrintable

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

            martins-v Martins Valkovskis
            zalex_ua Oleksii Zagorskyi
            Team D
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: