I've been trying to re-arrange a pretty flat json into structure with more depth, so far without any success. Here's my source data:
[ {
"id": "27",
"time": "2017-12-21 07:24:00",
"service_name": "prices",
"version": "61f4u8e",
"event": "Success"
},
{
"id": "28",
"time": "2017-12-21 07:23:00",
"service_name": "prices",
"version": "21c2f7d",
"event": "Fail"
},
{
"id": "29",
"time": "2017-12-21 07:21:00",
"service_name": "cart",
"version": "9ff24c4",
"event": "Success"
}
]
The result should look like this:
[
{
"name": "cart",
"data": [
{
"date": "2017-12-21 07:21:00",
"details": {
"event": "Success",
"version": "9ff24c4"
}
}
]
},
{
"name": "prices",
"data": [
{
"date": "2017-12-21 07:24:00",
"details": {
"event": "Success",
"version": "61f4u8e"
}
},
{
"date": "2017-12-21 07:23:00",
"details": {
"event": "Fail",
"version": "21c2f7d"
}
}
]
}
]
So, basically grouping by service_name and moving the other fields around a little.
So far I've managed to group, but only one level:
group_by(.service_name) | map({name: .[0].service_name, data: .})
How can I shuffle around the other values, assuming the input will always have all fields as in the example above?