Have a json that contains structure as shown below: What I'm trying is to group and merge data based on 'name' , for example the two examples below have same name i.e 'abc', so they will get merged into a single collection and 'id' and 'nested prop' will be an array under the 'name' with two contents
[{
"id" : [{"random" : "12345"}],
"name" : "abc",
"nestedprop" : {
"malfunc" : [
{
"Info" : {
"xyz" : [
{
"vamp" : "104531_0_46095",
"ramp" : {
"samp" : [
{
"int" : 532,
}
],
},
"class_unique_id" : "05451",
}
],
"nati" : 39237,
"apper" : 00,
"supp" : {
"sess" : ""
},
"session_id" : "42461920181213044516299872341"
}
},
{
"Info" : {
"xyz" : [
{
"vamp" : "104531_0_46095",
"ramp" : {
"samp" : [
{
"int" : 5325,
}
],
},
"class_unique_id" : "05451",
}
],
"nati" : 392537,
"apper" : 00,
"supp" : {
"sess" : ""
},
"session_id" : "42461920181213044516299872341"
}
},
]
},
},
{
"id" : [{"asdad" : "63653"}],
"name" : "abc",
"nestedprop" : {
"malfunc" : [
{
"Info" : {
"xyz" : [
{
"vamp" : "104531_0_46095",
"ramp" : {
"samp" : [
{
"int" : 532,
}
],
},
"class_unique_id" : "05451",
}
],
"nati" : 39237,
"apper" : 00,
"supp" : {
"sess" : ""
},
"session_id" : "42461920181213044516299872341"
}
},
{
"Info" : {
"xyz" : [
{
"vamp" : "104531_0_46095",
"ramp" : {
"samp" : [
{
"int" : 532,
}
],
},
"class_unique_id" : "05451",
}
],
"nati" : 39237,
"apper" : 00,
"supp" : {
"sess" : ""
},
"session_id" : "42461920181213044516299872341"
}
},
]
}
}]
Expected Result:
[{
"id" : {"0":[{"random" : "12345"}],"1":[{"random" : "12345"}]},
"name" : "abc",
"nestedprop" : {"0":[{"content from 1st obj"}],"1":[{"content from 1st obj"}]
},
{"id" : "0":[{"randsdaom" : "123sdas45"}]},
"name" : "def",
"nestedprop" : {"0":[{"content from 1st obj"}]}]
Note: I have achieved this using Mapreduce in Mongodb,however I wanted to try it out in Python
expected output."id":{[{"random" : "12345"}],[{"asdad" : "63653"}]},this is dictionary without any key, value pair, so correct it.