我有一个项目,我想从具有重复属性的json对象数组的文件中获取JSON数据:
一些文件:(每个对象在一行中,为简单起见,我对其进行了格式化)
{
"A":"ALL",
"B":"3349256522",
"Location":{
"Country":"USA"
},
"EffectiveDate":"2020-03-04T14:15:52.063Z",
"Demographic":{
"Q":"done",
"G":"ok",
"AppVersion":"1.3.4",
},
"ApplicationId":"92398723892937",
"Id":"23232993939333",
"CreationDate":"2020-03-04T14:15:52.063Z"
}
{
"A":"NONE",
"B":"8469256522",
"Location":{
"Country":"SPAIN"
},
"EffectiveDate":"2020-03-04T14:15:52.063Z",
"Demographic":{
"Q":"done",
"G":"ok",
"AppVersion":"1.3.5",
},
"ApplicationId":"92398723892937",
"Id":"23232993939333",
"CreationDate":"2020-03-09T14:15:52.063Z"
}
{
"A":"ALL",
"B":"8469256522",
"Location":{
"Country":"USA"
},
"EffectiveDate":"2020-03-04T14:15:52.063Z",
"Demographic":{
"Q":"done",
"G":"ok",
"AppVersion":"1.3.4",
},
"ApplicationId":"92398723892937",
"Id":"23232993939333",
"CreationDate":"2020-03-11T14:15:52.063Z"
}
我想获取某些特定项目的统计信息,例如Country和AppVersion。 如何使用NodeJ处理它以产生以下输出:
{
"stats":{
"Country":{
"USA":"2",
"SPAIN":"1"
},
"AppVersion":{
"1.3.4":"2",
"1.3.5":"1"
}
}
}
You can use array.reduce to accumulate the count values: