json - 使用 jq 替换 json 中的争论
问题描述
{
"containers": [
{
"args": [
"water",
"fight",
"--homein",
"$(POD_NAMESPACE).svc.cluster.local",
"--proxyLogLevel=warning",
"--proxyComponentLogLevel=misc:error",
"--log_output_level=default:info",
"ms-madison",
"--trust-domain=cluster.local"
]}]
}
我可以用一个丑陋的解决方案 .containers[0].args[8] |= "mr-harmison"' 用 mr-harmison 替换 ms-madison
ms-madison 可以出现在任何位置。你能建议我一个更好的方法来处理这个问题吗?
解决方案
一个平淡但强大的解决方案:
(.containers[0].args | index("ms-madison")) as $ix
| if $ix then .containers[0].args[$ix] = "mr-harmison" else . end
推荐阅读
- adsense - 折叠 Google Adsense Divs
- java - 如何在 Spring 中将 HTTP 参数与 @RequestBody 绑定
- android - RxSwift 中的 NetworkBoundResource
- c# - 如何在 RazorEngine 模板中使用 css/less 样式
- java - 滑动片段的导航(显示?)
- javascript - Jasmine:带有 Promise 返回的 callThrough 失败(Jasmine 2.x 和 Angular.io)
- model-view-controller - 设置剑道 NumericTextBoxFor 的格式
- kubernetes - 编织 kubernetes 中的就绪探测失败错误
- php - 如何修复无法在 laravel 中创建控制器更新配置文件
- android - 宽度 match_parent 时 drawableRight 靠近文本