简体   繁体   中英

helm convert map type data into json object

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

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 }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM