考虑以下 JSON:
{
"Company" : "ABC Company",
"Place" : {
"Bangalore" :{
"Address" : "MG Road",
"Phone" : ["988888","888866","365656"]
},
"Mubmai" : {
"Address" : "1st Main Road,West",
"Phone" : ["21212","123123","544455"]
}
}
}
现在我想将 JSON 展平,以便获得多个 JSON。对于上面的例子,扁平化的输出如下:
{
"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"
}
并且 JSON 结构不是固定的,它往往会改变,但扁平化仍然必须以相同的方式工作。有没有办法在 Node.js 中做到这一点?