# Infinity plugin + JSON + dashboard variables

**URL:** <https://community.grafana.com/t/infinity-plugin-json-dashboard-variables/132643>\
**Category:** Dashboards\
**Tags:** dashboard-variables, infinity-datasource, json\
**Created:** [September 21, 2024, 7:00pm UTC](https://community.grafana.com/t/infinity-plugin-json-dashboard-variables/132643 "2024-09-21T19:00:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gijbelsy](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@gijbelsy](https://community.grafana.com/u/gijbelsy)\
**Post date:** [September 21, 2024, 7:00pm UTC](https://community.grafana.com/t/infinity-plugin-json-dashboard-variables/132643/1 "2024-09-21T19:00:24Z")

</div>

I’m running Grafana on a Linux OS

The goal is to use a JSON to pass data to a variable.  
This variable will be used to modify (filter, visualisation name, timerange, …) a dynamic dashboard.

The variable is created on the dasboardsettings as ‘query’, and is named “testvar”.  
I have the following example data, as inline data for the infinity datasource

```auto
[
        {
            "entity":"GOOGL",
            "price": 2155.85,
            "time": 1653603843766
        },
        {
            "entity":"AAPL",
            "price": 143.78,
            "time":1653603943766
        }
    ]

```

In parsing options, I have defined the columns:  
entity, price, time.  
On the dashboard I want to (for example) visualize the value of the entity.  
This works as I enter `${testvar}`, “GOOGL” or “AAPL” is returned depending on the selection in the dashboard.  
However I also want to visualize the price and time.  
I’ve tried `${testvar:price}` but this only works when there are 2 columns defined.  
When I define a third column, everything returns the same value, no matter what I try.

Bottom line: I want to have a dropdown box that is populated with the “entity” of the json, and use the referencing data “price” and “time” in the dashboard.  
for example: `${testvar.price}` and `${testvar.time}`

Kind regards

---

<div class="post-metadata">

**Author:** ![dawiddebowski](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/dawiddebowski/32/49435_2.png) [@dawiddebowski](https://community.grafana.com/u/dawiddebowski)\
**Post date:** [September 21, 2024, 7:56pm UTC](https://community.grafana.com/t/infinity-plugin-json-dashboard-variables/132643/2 "2024-09-21T19:56:26Z")

</div>

Hi,

I’m not master of Infinity Plugin, so it might be not the best answer, but I think what is happening is that Grafana allows you to have key:value pairs as your variable (see [this link](https://community.grafana.com/t/referencing-key-value-variable-with-another-variable-as-the-key/82362/2)). As I’ve noticed, if you pass `${var:<whatever>}` you’ll get the value of your query, so that’s why it worked with one value and not with three columns.

What you can do is to use a couple of variables. The first one being the list of values of `entity` fields - let’s call it `type` variable.

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/2/d/2d6a7c3dec66b7981f9518a8f263dc2072148fe9.png)  
Then you could create another variable (let’s call it `price`) where you paste your data, select `entity` and `price` columns. In `Filter` option, you pass `contains("${type}", entity)`, which will limit the possible values of your the data only to the ones containing the `type` variable. In result, you’ll have just one variable which corresponds to the price of the entity you select in your `type` variable.  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/4/4/44a25fcc421aff5a17618851b226c15c2f4f1cdb.png)

You repeat this step for another variable `time` (which you do analogously to the `price` variable only changing the column from `price` to `time`). You can hide `price` and `time` variables. In your visualizations, you’ll use variables `price` and `time` wherever you wanted to use `testvar.price` and `testvar.time` but your end user will see only one variable to rule them all.

Disadvantages are that you have to create multiple variables and use them, even though they are not presented on the dashboard, but I don’t know better way to do this (and my knowledge says it might be impossible to do it the way you wanted with 3 columns in one variable).

---

<div class="post-metadata">

**Author:** ![gijbelsy](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@gijbelsy](https://community.grafana.com/u/gijbelsy)\
**Post date:** [September 21, 2024, 9:31pm UTC](https://community.grafana.com/t/infinity-plugin-json-dashboard-variables/132643/3 "2024-09-21T21:31:21Z")

</div>

Tried the above, but I couldn’t get a consistent solution.  
Sometimes I get the error ‘unsupported data format’ when creating the variable.

Strange thing, because I can’t figure out why since everyting is the same for each variable.  
Also the JSON I’ve provided are all strings.

---

<div class="post-metadata">

**Author:** ![solitcon](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@solitcon](https://community.grafana.com/u/solitcon)\
**Post date:** [September 22, 2024, 1:08am UTC](https://community.grafana.com/t/infinity-plugin-json-dashboard-variables/132643/4 "2024-09-22T01:08:30Z")

</div>

so you can only have 2 data points. which one can you live without?

you can choose uql then do this as an example

```auto
parse-json
| extend " __value"="entity", "__ text"="price"

```

with this text will be displayed, price would be the value for selected item

---

<div class="post-metadata">

**Author:** ![gijbelsy](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@gijbelsy](https://community.grafana.com/u/gijbelsy)\
**Post date:** [September 22, 2024, 11:51am UTC](https://community.grafana.com/t/infinity-plugin-json-dashboard-variables/132643/5 "2024-09-22T11:51:36Z")

</div>

With the combination of the answers from @solitcon and @dawiddebowski provided above I was able to figure out the solution.

_Note: I used a different dataset for this example. It’s still JSON, but the field names differ from my starting post._

```auto
[
  {
    "friendly_name": "Meting 1",
    "channel": "ch01",
    "current": "6",
    "starttime": "9",
    "stoptime": "17"
  },
  {
    "friendly_name": "Meting 2",
    "channel": "ch02",
    "current": "10",
    "starttime": "9",
    "stoptime": "17"
  }
]

```

The following dashboard variables are created:  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/5/9/595260aa99e2422954527e130abc7ed0d2f3a9f9.png)

First I created the variable that functions as the ‘master selector’ (type ‘Query’).  
This is the only one that is visible on the dashboard.  
For query options I used the following configuration:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/f/b/fb75afbc15a687100bab3f59932cfc6dd1fe62f3.png)  
This propagates a list with friendly names from which I can select, that hold a less readable value.  
This ‘value’ I use in further variable queries.

Second (this applies to all the other variables) I created variables that change depending on the first ‘master’ variable. These are also of type ‘Query’.  
For query options I used the following configuration:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/b/5/b5cfb32326c2b28826784407e2a4e85568d85878.png)  
Notice the ‘WHERE’ clause: this filters the returned values depending on the value of the ‘master’ variable (varMeting). The ‘:raw’ is to select only the value, and not the diplay name ()

```auto
parse-json
| where "channel" in (${varMeting:raw})
| extend "__value"="current"

```

I’ve repeated this proces for all the other variables I needed.  
Only changing the last line of UQL: in which I replace ‘current’ with the property I need.

```auto
| extend "__value"="current"

```

---

<div class="post-metadata">

**Author:** ![solitcon](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@solitcon](https://community.grafana.com/u/solitcon)\
**Post date:** [September 22, 2024, 3:04pm UTC](https://community.grafana.com/t/infinity-plugin-json-dashboard-variables/132643/6 "2024-09-22T15:04:19Z")

</div>

nice! also look into using the Business Variable plugin for nice layout instead of ugly drop downs

![image](https://us1.discourse-cdn.com/grafana/original/3X/0/1/0198355c55519f48d88a9595da7d628e482df932.png)
