我正在做一个项目,需要使用Google Maps位置记录Json(通过Google外卖)。我的主要问题是在json中有超过一百万个定位对象,并且有一些诸如“活动”之类的字段,例如,我不需要并且想要从所有对象中删除它们。是否可以使用任何软件一次从所有对象中删除不需要的字段,还是需要编写自己的代码来做到这一点?
位置对象的示例:
{
"timestampMs" : "0000000000000",
"latitudeE7" : 000000000,
"longitudeE7" : 000000000,
// above is what I need, below is what's left
"accuracy" : 15,
"altitude" : 77,
"verticalAccuracy" : 2,
"activity" : [ {
"timestampMs" : "0000000000004",
"activity" : [ {
"type" : "STILL",
"confidence" : 22
}, {
"type" : "IN_VEHICLE",
"confidence" : 21
}, {
"type" : "UNKNOWN",
"confidence" : 21
}, {
"type" : "IN_RAIL_VEHICLE",
"confidence" : 21
}, {
"type" : "ON_FOOT",
"confidence" : 13
}, {
"type" : "WALKING",
"confidence" : 13
}, {
"type" : "IN_ROAD_VEHICLE",
"confidence" : 13
}, {
"type" : "ON_BICYCLE",
"confidence" : 6
}, {
"type" : "IN_TWO_WHEELER_VEHICLE",
"confidence" : 6
}, {
"type" : "IN_FOUR_WHEELER_VEHICLE",
"confidence" : 6
}, {
"type" : "RUNNING",
"confidence" : 5
} ]
}
答案 0 :(得分:0)
最终没有找到软件,但是从代码角度看它非常简单,读取文件,将其转换为JSON,在locations数组上进行foreach循环,并删除所有要删除的属性。完成后,将其写入新的json文件。
nodejs代码解决方案:
var fs=require("fs");
var file=fs.readFileSync("C:\\Users\\User\\Desktop\\lochist.json",{"encoding":"utf-8"});
var obj=JSON.parse(file);
obj.locations.forEach(element => {
delete element.accuracy;
delete element.activity;
});
fs.writeFileSync('NewJSON.json',JSON.stringify(obj));
console.log('done');