I need to organize a list of events by the month they are scheduled to take place. Currently, I have an array with JSON objects for each event, but I want to display them in a specific format:
January
- event blabla 10/01/17
- event thisandthat 17/01/17
February
- event something 05/02/17
- event another something 13/02/17
...and so on
The way the JSON data is structured currently doesn't allow me to achieve this desired output. Is there a method to manipulate the JSON data to suit my needs?
This is how I am currently receiving my JSON data:
[{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-01-10"
},
{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-01-10"
},
{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-02-10"
},
{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-03-20"
},
{
"event_name":"blabla",
"event_location":"somewhere",
"event_date":"2017-05-05"
}]
The expected result should resemble this structure:
[{
"January": [{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-01-10"
},
{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-01-17"
}
]
},
{
"February": [{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-02-10"
},
{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-02-17"
}
]
},
{
"March": [{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-03-10"
},
{
"event_name": "blabla",
"event_location": "somewhere",
"event_date": "2017-03-17"
}
]
}
]
Is it possible to transform the existing JSON data into this new format?