I have a json in the following format. My requirement is to change the data if the "id" field is same then rest of the field should be made into a list. I tried looping it and referring other sample code but I couldn't get the required result. If the "id" is same then I should combine the rest of the field's value into a list and keeping the key as same. I tired to add values to new dictionary based on 'id' field but result was either last value or some thing like this
[
{
"time":" all dates ",
"author_id":"alll ",
"id_number":"all id_number",
"id":"all idd"
}
]
Received JSON :
data = [
{
"time":"2015/03/27",
"author_id":"abc_123",
"id":"4585",
"id_number":123
},
{
"time":"2015/03/30",
"author_id":"abc_123",
"id":"7776",
"id_number":122
},
{
"time":"2015/03/22",
"author_id":"abc_123",
"id":"8449",
"id_number":111
},
{
"time":"2012/03/30",
"author_id":"def_456",
"id":"4585",
"id_number":90
}
]
Required Output:
new_data = [
{
"time":[
"2015/03/27",
"2012/03/30"
],
"author_id":[
"abc_123",
"def_456"
],
"id":"4585",
"id_number":[
123,
90
]
},
{
"time":"2015/03/30",
"author_id":"abc_123",
"id":"7776",
"id_number":122
},
{
"time":"2015/03/27 05:22:42",
"author_id":"abc_123",
"id":"8449",
"id_number":111
}
]