[ZBX-21088] JSONPath cannot get keys instead of value Created: 2022 May 20  Updated: 2024 Apr 10  Resolved: 2022 Jun 13

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 6.0.3, 6.0.4
Fix Version/s: None

Type: Problem report Priority: Trivial
Reporter: Anonymouse Assignee: Konstantins Prutkovs (Inactive)
Resolution: Won't fix Votes: 0
Labels: lld, macros
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File screencapture-jsonpath-2022-05-26-10_35_26.png    
Team: Team C

 Description   

Hello,

I have a 1110 line JSON that I am referencing via an LLD Discovery Rule.

There is an array in the JSON that is 3 elements long with a bunch of subsequent segments.

Here is a snippet of my JSON, the array, keys, and segments I am referring to...

Ultimately I want to grab the keys of each element [0,1,2]. I found I can accomplish this with *~ here...
https://stackoverflow.com/questions/46471516/get-keys-in-json

Here is a picture of it working in jsonpath.com...

Here I am using it as an LLD Macro...

But I get the following error message: Cannot process LLD macro "{#MACRO}": unsupported construct in jsonpath starting with: "~]".

Is this a bug or limitation in Zabbix? Is there a different way to accomplish this?



 Comments   
Comment by Aigars Kadikis [ 2022 May 26 ]

Thank you for reaching out.

I can confirm that following input data:

{
    "data": [
        {
            
            "attr": {
                "name": "hello",
                "radio_bands": [
                    {
                        "enabled_alarms": "1C00",
                        "transceiver": 45.0
                    },
                    {
                        "enabled_alarms": "1C00",
                        "transceiver": 45.0
                    },
                    {
                        "enabled_alarms": "0C00",
                        "transceiver": 51.0
                    }
                ]
            }
        }
    ]
} 

with JSONPath:

$..[?(@.name=="hello")].radio_bands[*~]

Works under https://jsonpath.com/ but does not work with Zabbix 6.0.4 JSONPath preprocessing engine:

Comment by Anonymouse [ 2022 May 31 ]

Try it with JSONPath:

 

$..[?(@.name=="hello")].radio_bands.*~

 

 

Comment by Konstantins Prutkovs (Inactive) [ 2022 Jun 13 ]

Anonymouse aigars.kadikis it is possible to get the keys of the array elements with JsonPath in Zabbix. Namely:

$..[?(@.name=="hello")].radio_bands.*~

As per documentation of Zabbix:

  • Matched element names can be extracted by adding a ~ suffix to the JSONPath. It returns the name of the matched object or an index in string format of the matched array item. The output format follows the same rules as other JSONPath queries - definite path results are returned 'as is' and indefinite path results are returned in array. However there is not much point of extracting the name of an element matching a definite path - it's already known.

This is the case as we do not support JsonPath Plus specification, but we do support the ~ extension.

Generated at Wed Apr 16 20:59:55 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.