将多行JSON插入YAML
拥有一个看起来像这样的 configmap.yaml 文件:
apiVersion: v1
kind: ConfigMap
metadata:
name: someCF
data:
appsettings.k8s.json: |
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
还有另一个名为json1的json文件,我需要将其放入data.appsettings.k8s.json:
{
"Logging": {
"LogLevel": {
"Default": "Full",
"Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
如何更改 data.appsettings中的json .k8s.json ,看起来会这样:
apiVersion: v1
kind: ConfigMap
metadata:
name: someCF
data:
appsettings.k8s.json: |
{
"Logging": {
"LogLevel": {
"Default": "Full",
"Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
Have a ConfigMap.yaml file that looks like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: someCF
data:
appsettings.k8s.json: |
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
Also have another JSON file named JSON1 that I need to put into data.appsettings.k8s.json:
{
"Logging": {
"LogLevel": {
"Default": "Full",
"Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
How to change JSON in data.appsettings.k8s.json so it will look like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: someCF
data:
appsettings.k8s.json: |
{
"Logging": {
"LogLevel": {
"Default": "Full",
"Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,您还可以将文件作为字符串直接加载:
免责声明:我写了YQ
Note that you can also load the file as a string direct like this:
disclaimer: I wrote yq
您可以精心打印JSON文件,并将其作为参数传递给
YQ
。由于 mikefarah/yq 允许您更新YAML多行,您可以做。style 对于
appsettings.k8s.k8s.jsons.json
在文字
上,因此不必修改它,请使用
-i
或- Inplace
flag即可更新文件Inploph。在版本4.25.3
上测试You can pretty-print the JSON file and pass that as an argument to
yq
. Since mikefarah/yq allows you to update YAML multi-line, you could just do.The style for the
appsettings.k8s.json
is already atliteral
, so it doesn't have to be modifiedUse the
-i
or--inplace
flag to update the file inplace. Tested on version4.25.3