What are `toJson`, `fromYaml`, `fromJson` and `fromYamlArray` used for?
AdvancedConceptTemplating: Go Templates & Sprig
Answer
toJson: emit compact JSON, for example inside an annotation or a JSON config file.fromYaml/fromJson: parse a string into a dict, often the output ofincludeor.Files.Get, so you can merge or inspect it.fromYamlArray/fromJsonArray: parse into a list.
{{- $base := include "shop.podDefaults" . | fromYaml }}
{{- $merged := mergeOverwrite $base .Values.api.podOverrides }}
{{- toYaml $merged | nindent 6 }}
If parsing fails, fromYaml returns a dict with an Error key instead of failing, so check it in library code.
More on Templating: Go Templates & Sprig
What template language does Helm use?BeginnerWhat does the dot (`.`) mean in a Helm template?BeginnerWhat is `$` and when do you need it?IntermediateHow does whitespace control (`{{-` and `-}}`) work?BeginnerHow do `if`, `else if` and `else` evaluate truthiness?BeginnerWhat do `and`, `or`, `not`, `eq`, `ne`, `lt`, `gt` look like in Helm?Beginner