bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.54k stars 328 forks source link

Sort, Group & Count Object Array #1150

Open HabeebCycle opened 2 years ago

HabeebCycle commented 2 years ago

Hi,

I would be glad if anyone could provide the jolt spec for the following scenario:

Dates arrays with string numbers. For each number, I will like to form an array of objects with the corresponding date and the total number they occur.

Input JSON

{
  "temp" : {
    "March 29, 2022" : [ "0", "2", "2", "0" ],
    "March 28, 2022" : [ "0", "0", "2" ],
    "March 27, 2022" : [ "1", "1" ],
    "March 26, 2022" : [ "1" ]
  }
}

Desired Output JSON

{
  "tempSortCount": {
    "0": [
      {"March 29, 2022" : 2},
      {"March 28, 2022" : 2},
      {"March 27, 2022" : 0},
      {"March 26, 2022" : 0},
    ],
    "1": [
      {"March 29, 2022" : 0},
      {"March 28, 2022" : 0},
      {"March 27, 2022" : 2},
      {"March 26, 2022" : 1},
    ],
    "2": [
      {"March 29, 2022" : 2},
      {"March 28, 2022" : 1},
      {"March 27, 2022" : 0},
      {"March 26, 2022" : 0},
    ]
  }
}

Thank you