Simple JSON API & Dashboard Variables don't appear to work

  • What Grafana version and what operating system are you using?

Grafana Cloud Version 9

  • What are you trying to achieve?

I’m trying to add variables to a dashboard using an JSON feed → https://services.nvd.nist.gov/rest/json/cves/1.0?

  • How are you trying to achieve it?

I go to the dashboard that I want to add a variable too. I create the variable using the following param using SimpleJSON as my API.

Datasource = https://services.nvd.nist.gov/rest/json/cves/1.0?
Field = $.result.CVE_Items[*].cve.CVE_data_meta.ID

This returns a list of the data I want my dashboard to filter on.

I add this to the dashboard but when I select a particular CVE at random, it doesn’t get applied to any of the underlying tables. It’s almost like the variable is not dynamic.

  • What happened?

As above.

  • What did you expect to happen?

I should be to filter on the data that I want only to show.

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

N/A

  • Did you follow any online instructions? If so, what is the URL?

NA/

how are the underlying queries using this variable? can you please share?

I presume you mean this? See image.

As you can see, I’m just doing something very basic at the moment. I’m polling the data and looking to just view CVE-2022-32561. I’m yet to append any additional fields.

does not look like you are using the variable (from the drop down) anywhere in your A query. having a variable in of itself does not mean it will do something as far as I understand it. you have to use it in your queries

Hmmm there doesn’t appear to be any viable option to add this. Not at least using this Simple JSON api.

take a look at this, it should help out

https://marcus.se.net/grafana-json-datasource/query-editor#params

Thanks for the advice. I feel like what I’m trying to do isn’t possible with using the Simple JSON api. I’ll keep playing around and see if I can work it out.

hi louisleedavies,
would you use a variable in queries to filter data successfully?
I use JSONPath to query data: $.result.item[?(@.Name==“$variable”)].value
but I still got no data

Welcome

I would highly recommend using infinity plugin and also maybe try out jsonata query language

Can you please post sample json data you are trying to filter?

1 Like

Glad to hear from you.
In this case, I want to display ‘SeismicIntensity’ in different regions by selecting different ‘StationName’.

Sample json data:
{
“records”: {
“Earthquake”: [
{
“EarthquakeNo”: 112033,
“Intensity”: {
“ShakingArea”: [
{
“EqStation”: [
{
“StationName”: “Hehuanshan”,
“SeismicIntensity”: “3”
},
{
“StationName”: “Shetou”,
“SeismicIntensity”: “4”
}
]
},
{
“EqStation”: [
{
“StationName”: “Taichaung”,
“SeismicIntensity”: “5”
},
{
“StationName”: “Tainan”,
“SeismicIntensity”: “3”
}
]
}
]
}
},
{
“EarthquakeNo”: 112034,
“Intensity”: {
“ShakingArea”: [
{
“EqStation”: [
{
“StationName”: “Nantou”,
“SeismicIntensity”: “4”
},
{
“StationName”: “Taidong”,
“SeismicIntensity”: “2”
}
]
},
{
“EqStation”: [
{
“StationName”: “Taipei”,
“SeismicIntensity”: “3”
},
{
“StationName”: “Yilan”,
“SeismicIntensity”: “6”
}
]
}
]
}
}
]
}
}

Steps:
First, I create a variable(named as StationName) by using JSONPath:
$.records.Earthquake[].Intensity.ShakingArea[].EqStation[*].StationName

Then, I create a panel in dashboard and query the data by using JSONPath:
$.records.Earthquake[].Intensity.ShakingArea[].EqStation[?(@.StationName==“$StationName”)].SeismicIntensity

But It returns no data.
it only displays all data by using JSONPath:
$.records.Earthquake[].Intensity.ShakingArea[].EqStation[*].SeismicIntensity

1 Like

please properly format the json blob of data you posted?

sorry, I format the data.

{
	"records": {
		"Earthquake": [
			{
				"EarthquakeNo": 112033,
				"Intensity": {
					"ShakingArea": [
						{
							"EqStation": [
								{
									"StationName": "Hehuanshan",
									"SeismicIntensity": "3"
								},
								{
									"StationName": "Shetou",
									"SeismicIntensity": "4"
								}
							]
						},
						{
							"EqStation": [
								{
									"StationName": "Taichaung",
									"SeismicIntensity": "5"
								},
								{
									"StationName": "Tainan",
									"SeismicIntensity": "3"
								}
							]
						}
					]
				}
			},
			{
				"EarthquakeNo": 112034,
				"Intensity": {
					"ShakingArea": [
						{
							"EqStation": [
								{
									"StationName": "Nantou",
									"SeismicIntensity": "4"
								},
								{
									"StationName": "Taidong",
									"SeismicIntensity": "2"
								}
							]
						},
						{
							"EqStation": [
								{
									"StationName": "Taipei",
									"SeismicIntensity": "3"
								},
								{
									"StationName": "Yilan",
									"SeismicIntensity": "6"
								}
							]
						}
					]
				}
			}
		]
	}
}
1 Like

This is using infinity plugin, using jsonata. If you want to select multiple from the drop down you use this UQL query with jsonata

parse-json
| jsonata "$.records.Earthquake.Intensity.ShakingArea.EqStation[StationName in [${stationname:singlequote}]][]"

if you want to use one station at a time you use

| jsonata "$.records.Earthquake.Intensity.ShakingArea.EqStation[StationName = '$stationname'][]"
1 Like

I solved it.
Really grateful to you for your help!!

1 Like