Interview Prep/Helm/Templating: Go Templates & Sprig

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 of include or .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.

All Helm questions Roadmap: Helm

More on Templating: Go Templates & Sprig