How to flatten nested objects on keys of an object to have a group of arrays with single depth objects - Infinity Datasource

Hi,

I’m trying to flatten nested objects on keys of an object to have a group of arrays with single depth objects.

I’m using as an example the information of this stackoverflow post (with the only difference that I’m using “_” instead of “.” to create the new field names:

Here is the working example in JSONata Exerciser, that is working for an object:
https://try.jsonata.org/OGavZ0Ao_

I tried on Grafana using Infinity with UQL, and is working ok for an object:

But not for an array of objects:

Does anybody know how to adapt this UQL/JSONata:

parse-json
| jsonata "($fn := function($o, $prefix) {$each($o, function($v, $k) {($name := $join([$prefix,$k], '_');$type($v) = 'object' ? $fn($v, $name): {$name: $v})}) ~> $merge()};$fn($))"

To flatten not only a single object, but all the objects in an array?

I know that I can flatten all the fields with this UQL example:

parse-json
| jsonata "$.*"

But I need that the resulting field name of every field is the join of the joined fields, like the first example of an object that is working.

Thanks in advance for your help.

Regards,
Alejandro