Consider the following JSON:
{
"Company" : "ABC Company",
"Place" : {
"Bangalore" :{
"Address" : "MG Road",
"Phone" : ["988888","888866","365656"]
},
"Mubmai" : {
"Address" : "1st Main Road,West",
"Phone" : ["21212","123123","544455"]
}
}
}
Now I want to flatten up the JSON so that I get multiple JSON. For the above example the flattened output would be as follows:
{
"Company" : "ABC Company",
"Place" : "Bangalore",
"Address" : "MG Road",
"Phone" : "988888"
},
{
"Company" : "ABC Company",
"Place" : "Bangalore",
"Address" : "MG Road",
"Phone" : "888866"
},
{
"Company" : "ABC Company",
"Place" : "Bangalore",
"Address" : "MG Road",
"Phone" : "365656"
},
{
"Company" : "ABC Company",
"Place" : "Mubmai",
"Address" : "1st Main Road,West",
"Phone" : "21212"
},
{
"Company" : "ABC Company",
"Place" : "Mubmai",
"Address" : "1st Main Road,West",
"Phone" : "123123"
},
{
"Company" : "ABC Company",
"Place" : "Mubmai",
"Address" : "1st Main Road,West",
"Phone" : "544455"
}
And the JSON structure is not fixed it tend to change, but still the flattening has to work the same way. Is there any way to do this in Node.js?