英文:
helm convert map type data into json object
问题
我可以帮你翻译这段内容。以下是翻译的结果:
我在我的values.yaml文件中有地图数据。
values.yaml文件内容如下:
shapes:
"FIRST SHAPE": "square"
"SECOND SHAPE": "circle"
"THIRD SHAPE": "triangle"
我需要将这些数据转换为JSON格式,并添加额外的JSON键值对属性"FOURTH_SHAPE":"rectangle",该属性在values.yaml文件中不存在。
我希望最终的JSON格式如下:
{"FIRST SHAPE": "square","SECOND SHAPE": "circle","THIRD SHAPE": "triangle","FOURTH_SHAPE":"rectangle"}
请问如何实现这个目标?我尝试了toJson函数,但它没有起作用。非常感谢您的帮助。
英文:
i have map data in my values.yaml
values.yaml
shapes:
"FIRST SHAPE": "square"
"SECOND SHAPE": "circle"
"THIRD SHAPE": "triangle"
i need to convert this as json in my config-map. Also i need to add additional json key value attribute "FOURTH_SHAPE":"rectangle" which will not be available in values.yaml.
I want end json to be
{"FIRST SHAPE": "square","SECOND SHAPE": "circle","THIRD SHAPE": "triangle","FOURTH_SHAPE":"rectangle"}
how do i get this done? i tried toJson function and it doesn't work. Any help appreciated
答案1
得分: 2
{{ merge .Values.shapes (dict "FOURTH_SHAPE" "rectangle") | toJson }}
如果你只想添加一个单独的值,你也可以使用set。
{{ set .Values.shapes "FOURTH_SHAPE" "rectangle" | toJson }}
英文:
Use the toJson function annd one of the merge variants.
{{ merge .Values.shapes (dict "FOURTH_SHAPE" "rectangle") | toJson }}
If you only want to add a single value, you can also use set.
{{ set .Values.shapes "FOURTH_SHAPE" "rectangle" | toJson }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论