Using JSONata with Grafana for using with Infinity data source plugin

Hey guys, I see a lot of people mention using jsonata with grafana. Is this a plugin you just installl? I dont understand how to go about using jsonata in conjunction with a plugin like say infinity plugin.

in infinity, Its a little more obscure than it used to be, but if you make your parser uql, you can use a command for jsonata https://grafana.com/docs/plugins/yesoreyeram-infinity-datasource/latest/query/uql/#jsonata

Thanks for the quick response. Sorry for the silly question but I am new to both infinity and jsonata.

How would this query look if I was trying to put it into infinity? Simple queries are pretty straight forward. For example I can do this with no problem:

curl -XGET "<http://localhost:9200/_search>"

but something like

{
  "query": {
    "bool": {
      "must": [
        {
          "regexp": {
            "name.keyword": ".*/modem-state"
          }
        },
        {
          "term": {
            "serialNumber.keyword": "1234"
          }
        }
      ]
    }
  }
}```


Is a lot more complicated.

Is there support for more complex queries?

Im sorry, I am not familiar with XGET or sending a data payload with a GET. If you can send this as query parameters, that will work and the infinity datasource has fields for that

Heres a good sandbox with some infinity/json examples https://play.grafana.org/d/infinity-json/json-with-infinity?tab=queries

For this I think you could use Elasticsearch datasource (at least it resembles Elasticsearch query :smile:)

how would you run that query in tools such as insomnia or postman?

as you can see here under the hood infinity is doing a curl call

so you need to change things to
POST to get

therein you provide your opensearch json query data a la -d or --data

Thank you, I was stuck on this for a while. I am new to infinity plugin and jsonata so was very confused initially.

I tried to use that but I have an issue where I am trying to extract values from an array, I was told jsonata could help with this, thats why im giving this a shot

No worries, thank you for those resources, they ended up pointing me in the right direction!

what does the data returned look like? post json obfuscate it if needed

Like this I am pretty close to the result I want. Right now I am trying to make it so that the values inside of the “values” array are returned as just a single element. The values array is an array with a single element.

UQL query:

  scope "hits.hits"
  jsonata "$map(_source, function($v, $k) {($k='values') ? $v[0] : $v})"```

oh so I already answered that for you in the grafana forum.

Oh yeah I didn’t realize it was you . I have already made a lot of progress just off the documentation you sent. Thanks

https://community.grafana.com/t/opensearch-data-coming-back-as-array/126822/9

ዮስያስ (yosiasz) = Josiah :wink:

Nah fr tho you got no idea how much help you’ve been. Thanks

send some:beer: or :coffee: then :laughing: