Infinity plugin , cant parse data with time series panel with multiple nested objects per time field

I am using the Infinity plugin with an external API, trying to visualize it in a time series panel, but i am unable to parse the nested objects and tie them together, with the corresponding time field. This is an example of the API response

[
  {
    "time": "1732550700",
    "data": [
      {
        "dev_intf": "Device:internal12",
        "sent_kbps": "1768.23"
      },
      {
        "dev_intf": "Device:Ruckus",
        "sent_kbps": "1537.48"
      },
      {
        "dev_intf": "Device:internal5",
        "sent_kbps": "870.26"
      }
    ]
 },
     "time": "1732551900",
    "data": [
      {
        "dev_intf": "Device:internal12",
        "sent_kbps": "2359.98"
      },
      {
        "dev_intf": "Device:Ruckus",
        "sent_kbps": "2102.95"
      },
      {
        "dev_intf": "Device:APs",
        "sent_kbps": "120.83"
      }
    ]
  }
]

I have tried to create the panel with transformations and UQL but i cant seem to get it right. Any help would be appreciated.

Hi,

I’ve managed to (hopefully) do what you asked for with following JSONata code:

$reduce(
    $map($, function($v) {
        $map($v.data, function($val) {
            {
                "time": $fromMillis($number($v.time) * 1000),
                "value": $number($val.sent_kbps),
                "device": $val.dev_intf
            }
        })
    })
, $append, [])

to achieve such table:

Then, after two transformations:

I’ve got the chart:

Maybe there’s an easier or more proper way to do that, but I’m not a jsonata expert :smile:

3 Likes

Thanks a bunch, i really appreciate the help. It works perfectly.

1 Like

also another approach less verbose?

$.data.{
    'time': %.time,
    'metric': dev_intf,
    'value': sent_kbps
}

https://try.jsonata.org/fsUn3LSQ_

parse-json
| jsonata "$.data.{'time': $fromMillis($number(%.time) * 1000),'metric': dev_intf,'value': sent_kbps}"
| pivot sum("value"), "time", "metric"
3 Likes