I have a JSONArray which contains multiple JSONObjects and each JSON object represents a row of data. (Like a SQL row)
JSON Example(JSON is dynamic)
[{
"col1": "a1",
"col2": "b1",
"col3": 10
},
{
"col1": "a1",
"col2": "b1",
"col3": 11
},
{
"col1": "a2",
"col2": "b2",
"col3": 5
},
{
"col1": "a2",
"col2": "b2",
"col3": 7
}]
A list containing the columns on which group by has to happen:
Example:
["col1","col2","MAX(col3)"]
Finally, the aggregate that has to be applied, SUM,MIN,MAX and COUNT. Also the column on which the aggregate has to be applied:
Expected Output (Example 1): WITH aggregate being SUM
[{
"col1": "a1",
"col2": "b2",
"col3": 21
},
{
"col1": "a2",
"col2": "b2",
"col3": 12
}]
In the above JSON Col1,Col2,Col3 represents the different fields.
For Eg :
[
{
"PayrollID" : "101",
"SSN" : "123456789",
"BatchID" : "123",
"PayRate" : "12",
"Hours" : "5"
},
{
"PayrollID" : "101",
"SSN" : "123456789",
"BatchID" : "123",
"PayRate" : "12",
"Hours" : "10"
},
{
"PayrollID" : "101",
"SSN" : "123456789",
"BatchID" : "123",
"PayRate" : "14",
"Hours" : "12"
}
]
- if List containing the Columns on which Group by has to happen
["PayrollID","SSN","BatchID","PayRate","SUM(Hours)"]
Result
[
{
"PayrollID" : "101",
"SSN" : "123456789",
"BatchID" : "123",
"PayRate" : "12",
"Hours" : "15"
},
{
"PayrollID" : "101",
"SSN" : "123456789",
"BatchID" : "123",
"PayRate" : "14",
"Hours" : "12"
}
]
if List containing the Columns on which Group by has to happen
["PayrollID","SSN","BatchID","MIN(PayRate)","SUM(Hours)"]
Result
[
{
"PayrollID" : "101",
"SSN" : "123456789",
"BatchID" : "123",
"PayRate" : "12",
"Hours" : "27"
}
]
I am looking for a solution which is similar to the jasson library(JAVA).
you can try this
json
UPDATE
json