Hello,
I have a simple Grafana dashboard and there is an issue regarding parsing of JSON values using JSONPath language when in variable “Multi-value” is selected.
Here is the issue:
I have a variable which Queries “JSON API” datasource with the following parameters:
Type: Query
Name: tracker_id
Method: POST
Path: /tracker/list
Body:
{“hash”:“${hash_variable}”}
Multi-value: Enabled
Include all: Disabled
Fields:
- JSONPath: $.list[*].id
The preview works perfectly well and I receive tracker IDs in the preview.
Here is how the /tracker/list API responds in general:
{
"list": [
{
"id": 2829403,
"label": "TruckN12894j32",
"group_id": 0,
"source": {
"status_listing_id": 116518,
"id": 723127,
"device_id": "164382878878",
"blocked": false,
"creation_date": "2022-12-20",
"tariff_id": 17129,
"model": "navixymobile_xgps",
"tariff_end_date": "2024-09-01",
"phone": null
},
"tag_bindings": [
{
"tag_id": 396232,
"ordinal": 1
}
],
"clone": false
},
{
"id": 2903030,
"label": "FMC130",
"group_id": 0,
"source": {
"status_listing_id": null,
"id": 10159737,
"device_id": "111222333444556",
"blocked": false,
"creation_date": "2023-08-03",
"tariff_id": 17132,
"model": "telfmu130_telfmb130",
"tariff_end_date": "2025-03-29",
"phone": "079123122312"
},
"tag_bindings": [
{
"tag_id": 412763,
"ordinal": 1
},
{
"tag_id": 412764,
"ordinal": 2
}
],
"clone": false
}
],
"success": true
}
And everything works perfectly well, until I enable the option “Multi-value:Enabled”.
Whenever the option is selected and at least two trackers are selected in the drop down menu of the dashboard, Grafana brakes the JSON validity by inserting the “{ }” braces into a JSON array.
I enter the variable in another request body for forming a dashboard cell,
the body of the other request looks like this:
{"hash":"${hash}", "trackers":[$tracker_id], "allow_not_exist": true, "list_blocked": true}
OR
{"hash":"${hash}", "trackers":[${tracker_id}], "allow_not_exist": true, "list_blocked": true}
The braces are always inserted into the “trackers” array on multiple choice of the variable in the dashboard.
Here is what Grafana payload looks like in this case:
{“hash”:“abcdabcdabcdabcd777”, “trackers”:[{2829403,2903030}], “allow_not_exist”: true, “list_blocked”: true}
As you can see, the braces “{ }” brake the JSON validity and I cannot proceed with further using the dashboard with Multi-value enabled option.
Could you please clarify how can I avoid this breaking of JSON validity?
If I use a JSONPath evalutaor with the exact same JSON, I receive correct results:
However, Grafana, for some reason inserts the bracers in the request payload which prevents the request from being correctly responded.
Environment (with versions):
- Grafana version: Grafana v10.4.0 (03f502a94d)
- Operating system: Dockered
- Browser: Chrome Version 128.0.6613.85 (Official Build) (64-bit)
- Datasource version(s) (prometheus, graphite, etc.): JSON API
- Plugins: -