Hi,
I'm trying to transform a API result to display on a worldmap.
The result looks like:
{
"payload": [
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 64306,
"probability_percent": 0.635,
"group_id": "1"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 66156,
"probability_percent": 0.574,
"group_id": "1"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 68006,
"probability_percent": 0.755,
"group_id": "1"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 69856,
"probability_percent": 0.665,
"group_id": "1"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 2293556,
"probability_percent": 0.72,
"group_id": "2"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 2295406,
"probability_percent": 0.562,
"group_id": "2"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 2297256,
"probability_percent": 0.636,
"group_id": "2"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 2299106,
"probability_percent": 0.548,
"group_id": "2"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 2300956,
"probability_percent": 0.742,
"group_id": "2"
},
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 2302806,
"probability_percent": 0.655,
"group_id": "2"
},
etc...
{
"id": "115",
"sample_time": "2021-04-25T14:00:00.000Z",
"lat": -20.00,
"lon": 150.00,
"distance_mm": 3562656,
"probability_percent": 0.584,
"group_id": "11"
}
]
and I need to transform it to something like:
[
{
"name": "group_1_mean",
"layer": "leaks",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 67.081,
"lat": -20.00,
"lon": 150.00
},
{
"name": "group_1_min",
"layer": "leaks",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 64.306,
"lat": -20.00,
"lon": 150.00
},
{
"name": "group_1_max",
"layer": "leaks",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 69.856,
"lat": -20.00,
"lon": 150.00
},
{
"command": {
"lat": -20.00,
"lon": 150.00,
"zoom": 17
}
}
]
trying with JSONata (https://try.jsonata.org/KXi7Dpz2-) I got:
{
"1": {
"name": "group_1_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 67.081,
"lat": -20,
"lon": 150
},
"2": {
"name": "group_2_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2298.181,
"lat": -20,
"lon": 150
},
"3": {
"name": "group_3_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2466.531,
"lat": -20,
"lon": 150
},
"4": {
"name": "group_4_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2477.631,
"lat": -20,
"lon": 150
},
"5": {
"name": "group_5_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2498.906,
"lat": -20,
"lon": 150
},
"6": {
"name": "group_6_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2591.406,
"lat": -20,
"lon": 150
},
"7": {
"name": "group_7_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2657.081,
"lat": -20,
"lon": 150
},
"8": {
"name": "group_8_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2666.331,
"lat": -20,
"lon": 150
},
"9": {
"name": "group_9_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2692.231,
"lat": -20,
"lon": 150
},
"10": {
"name": "group_10_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 2727.381,
"lat": -20,
"lon": 150
},
"11": {
"name": "group_11_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": 3541.381,
"lat": -20,
"lon": 150
}
}
by using the JSONata:
payload {
`group_id`: {
"name": "group_" & $distinct(group_id) & "_mean",
"layer": "mylayer",
"options": {
"stroke": true,
"color": "#910000",
"weight": 4,
"opacity": 0.5,
"fill": false,
"fillColor": null,
"fillOpacity": 0.2
},
"radius": $average(distance_mm) / 1000,
"lat": $distinct(lat),
"lon": $distinct(lon)
}
}
But I can not workout how to remove the group numbers i.e. { "1":{}, "2":{}}
.
So just reaching out to see if anyone has any ideas.
Thank for the help.