【发布时间】:2017-12-26 20:39:42
【问题描述】:
我有一个 messages.json 文件
[
{
"id": "title",
"description": "This is the Title",
"defaultMessage": "title",
"filepath": "src/title.js"
},
{
"id": "title1",
"description": "This is the Title1",
"defaultMessage": "title1",
"filepath": "src/title1.js"
},
{
"id": "title2",
"description": "This is the Title2",
"defaultMessage": "title2",
"filepath": "src/title2.js"
},
{
"id": "title2",
"description": "This is the Title2",
"defaultMessage": "title2",
"filepath": "src/title2.js"
},
]
我想创建一个对象
{
"title": "Dummy1",
"title1": "Dummy2",
"title2": "Dummy3",
"title3": "Dummy4"
}
从顶部开始。 到目前为止我有
jq '.[] | .id' src/messages.json;
它确实给了我 ID 如何添加一些随机文本并像上面一样制作新对象?
我们也可以创建一个新的 JSON 文件并使用 jq 将新创建的对象写入它吗?
【问题讨论】: