grafana-json-datasource icon indicating copy to clipboard operation
grafana-json-datasource copied to clipboard

JSONPath and JSONata

Open trungswat opened this issue 4 years ago • 4 comments
trafficstars

Hi,

Thank you for your hard work, this plugin works pretty well now.

But I found something does not work well in query with a variable in both JSONpath and JSONata Here is my problem:

  • Using JSONPath:

$.DevInfo[?(@.Date=="$Date")].Projects[?(@.ProjectName =~ /.*Test/ )] --> not work with regex /.*Test/

  • Using JSONata

$.DevInfo[?(@.Date=="$Date")].Projects[*].ProjectName --> work well

DevInfo[Date=$Date)].Projects.ProjectName --> not work

Hope you could help me. Thank you in advance.

trungswat avatar Oct 06 '21 14:10 trungswat

I'm not sure I understand the problem. Could you provide an example JSON document and a query that demonstrates the issue, so that I can test it myself?

marcusolsson avatar Oct 13 '21 13:10 marcusolsson

I've also seen oddities with the JSONPath implimentation, two I've run into:

  • If root JSON object starts with [, filters don't work as expected
  • the in filter doesn't seem to be working

For the later, here's an example: object:

{
   "store" : {
      "book" : [
         {
            "category" : "reference",
            "author" : "Nigel Rees",
            "title" : "Sayings of the Century",
            "price" : 8.95
         },
         {
            "category" : "fiction",
            "author" : "Evelyn Waugh",
            "title" : "Sword of Honour",
            "price" : 12.99
         },
         {
            "category" : "fiction",
            "author" : "Herman Melville",
            "title" : "Moby Dick",
            "isbn" : "0-553-21311-3",
            "price" : 8.99
         },
         {
            "category" : "fiction",
            "author" : "J. R. R. Tolkien",
            "title" : "The Lord of the Rings",
            "isbn" : "0-395-19395-8",
            "price" : 22.99
         }
      ],
      "bicycle" : {
         "color" : "red",
         "price" : 19.95
      }
   },
   "expensive" : 10
}

JSONPath:

$.store.book[?(@.category in ['fiction', 'non-fiction'])].author

Expected result:

[
   "Evelyn Waugh",
   "Herman Melville",
   "J. R. R. Tolkien"
]

u2mejc avatar Aug 25 '22 21:08 u2mejc

@u2mejc For your query, the following works for me:

store.book[category in ['fiction', 'non-fiction']].author

tiebingzhang avatar Jan 10 '23 18:01 tiebingzhang

For me this does not work. is there a fix for this issue

Abuu001 avatar Sep 08 '23 12:09 Abuu001