I have this project where I want to get the JSON data from a file with array of json objects with repetitive attributes:
some-file: (each object is in 1 line, for simplicity I formatted it)
{
"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"
}
I would like to get some statistics for specific items, Country and AppVersion. How can I process it using NodeJs to produce this output:
{
"stats":{
"Country":{
"USA":"2",
"SPAIN":"1"
},
"AppVersion":{
"1.3.4":"2",
"1.3.5":"1"
}
}
}
Also, the input file 'some-file' is not a valid JSON file, any recommendation how to convert it to be valid (in code) ?
The original file is (1 line each object):
{ "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":"ALL", "B":"3349256522", "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-04T14:15:52.063Z"}
{ "A":"ALL", "B":"3349256522", "Location":{ "Country":"ITALY" }, "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"}