If I have an input of a list of JSON objects. How do I go about nesting the data in Java by the date, and then the category in and also sorting it by date in descending order?
Input:
{ "data":[{
"date": "2015-02-26",
"buyer": "Ryan",
"category": "clothes",
"quantity":"10.0"
},
{
"date": "2015-02-18",
"buyer": "Lisa",
"category": "food",
"quantity": "2.0"
},
{
"date": "2015-02-18",
"buyer": "Brian",
"category": "food",
"quantity": "11.0",
},
{
"date": "2015-02-26",
"buyer": "Jim",
"category": "clothes",
"quantity": "20.0",
},
{
"date": "2015-02-26",
"buyer": "Tom",
"category": "food",
"quantity": "40.0",
},
{
"date": "2015-02-18",
"buyer": "Alyssa",
"category": "clothes",
"quantity": "13.0",
}]
}
You can see in my below output, that I am trying to group the data by the date first, and then within the date I want to group the objects by the category.
Desired Output:
{
"2015-02-26”:{
“clothes”:[{
"date": "2015-02-26",
"buyer": "Ryan",
"category": "clothes",
"quantity":"10.0"
},
{
"date": "2015-02-26",
"buyer": "Jim",
"category": "clothes",
"quantity": "20.0",
}],
"food":[{
"date": "2015-02-26",
"buyer": "Tom",
"category": "food",
"quantity": "40.0",
}]
}
"2015-02-18":{
“clothes”:[{
"date": "2015-02-18",
"buyer": "Alyssa",
"category": "clothes",
"quantity": "13.0",
}],
"food":[{
"date": "2015-02-18",
"buyer": "Lisa",
"category": "food",
"quantity": "2.0"
},
{
"date": "2015-02-18",
"buyer": "Brian",
"category": "food",
"quantity": "11.0",
}]
}
}