我有一个 JSON 文件:
{
"header": {
"uuid": "c578592a-a751-4993-9060-53f488597e59",
"timestamp": 1522938800,
"productionDateTime": "2018-04-05T14:33:20.000+00:00",
"producers": {
"operator": null,
"application": {
"com.example": {
"id": {
"string": "1"
},
"name": {
"string": "Test"
}
}
},
"station": null,
"equipment": null,
"partner": null,
"flow": null
},
"correlationContext": {
"array": [{
"correlationId": "98440498-3104-479e-9c99-f4449ba8f4b6",
"correlationDateTime": {
"string": "2018-04-05T14:30:39.000+00:00"
}
}]
}
},
}
我想创建 n 个文件来复制 JSON 文件,但具有随机的correlationId 和correlationDateTime。
您有什么建议或建议吗?非常感谢!
最佳答案
使用jq
并将生成适当的随机值作为读者的练习:
$ jq --arg cid "foo" --arg cdt "bar" '
.header.correlationContext.array[0]={
correlationId: $cid,
correlationDateTime: {string: $cdt}
}' tmp.json
关于json - 生成文件并替换生成文件中模板文件中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49675733/