【发布时间】:2020-07-07 03:04:25
【问题描述】:
我们有一个带有如下对象的 json
JSON 之前
// comment 1
{
"version": "2.0.0",
"tasks": [{
"type": "task1",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"aaa": "never"
}
}]
}
// comment 2
JSON 之后
现在我想添加一个新对象一个新任务(任务 2)
// comment 1
{
"version": "2.0.0",
"tasks": [{
"type": "task1",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"aaa": "never"
}
},
{
"type": "task2",
"script": "watch",
"problemMatcher": "$tsh",
"isBackground": true,
"presentation": {
"aaa": "never"
}
}
]
}
// comment 2
这里的诀窍是,我需要更新对象而不更改结构、行或注释。我尝试使用 jsonParse,但它不起作用
在 javascript/nodejs 中可以吗?
【问题讨论】:
标签: javascript node.js json typescript abstract-syntax-tree