Search code examples
jsongrafanajsonata

Building JSON Path for a datalist


I am trying to import some data from an API and graph it using Grafana, the issue is the json is structured with no keys. They are simply dates and counts shown below:

[["10","2024-01-07"],["241","2024-01-08"],["288","2024-01-09"],["692","2024-01-10"],["286","2024-01-11"],["263","2024-01-12"],["11","2024-01-13"],["83","2024-01-15"],["220","2024-01-16"],["228","2024-01-17"],["170","2024-01-18"],["250","2024-01-19"],["11","2024-01-20"],["10","2024-01-21"],["8","2024-01-22"]]

I'm not sure if I'm going about this the right way, but I'm trying to create a field for the count and a field for the dates. Any help would be nice. thank you in advance.

enter image description here


Solution

  • You can use the map operator to iterate over each tuple as follows:

    $.({
      "date": $[1],
      "count": $[0]
    })
    

    Try it on the JSONata playground: https://stedi.link/k15AHBV