在运行时替换json中的值 [英] Replace value in json during run time
本文介绍了在运行时替换json中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在运行时替换json中的值,即
I am trying to replace value on run time in json i.e.
旧
{
"containerDefinitions": [{
"name": "containername",
"image": "myimage",
"memory": 512,
"cpu": 1,
"essential": true,
"portMappings": [{
"hostPort": 80,
"containerPort": 80,
"protocol": "tcp"
}]
}],
"volumes": [],
"family": "containername"
}
新的应该是
{
"containerDefinitions": [{
"name": "containername",
"image": "new image",
"memory": 512,
"cpu": 1,
"essential": true,
"portMappings": [{
"hostPort": 80,
"containerPort": 80,
"protocol": "tcp"
}]
}],
"volumes": [],
"family": "containername"
}
- 旧值:-"image":"myimage"
- 新值:-图片":新图片"
我想用bash做.有什么最好的办法吗?我们可以通过jq做吗?
I want to do in bash. Is there any best way to do? Can we do through jq?
推荐答案
您可以为此使用jq:
jq '.containerDefinitions[].image="new image"' old.son
这篇关于在运行时替换json中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文