1

Im using Helm.

I have a settings.json file containing the following configuration:

"CustomSetting": {
  "ArrayOfArrays": {{ .Values.customSetting.arrayOfArrays | toJson }}
}

And my values.yaml file contains the following values:

customSetting:
  arrayOfArrays: [
      [ "someValue1", "someValue2" ],
      [ "anotherValue3", "anotherValue4" ]
  ]

My problem is that I cannot run my chart with this setup since I get the following error:

unable to parse YAML: error converting YAML to JSON: yaml: line X: did not find expected key

How do I get this nested array in my settings.json file?

Hristo
  • 1,805
  • 12
  • 21
  • Where is the `settings.json` file used? (Injected into a ConfigMap?) More specifically, do you use [the `tpl` function](https://helm.sh/docs/howto/charts_tips_and_tricks/#using-the-tpl-function) to expand the template in the JSON file? Editing the question to show how you're accessing the `settings.json` file would be helpful. – David Maze Nov 04 '21 at 11:07
  • (If you're getting an "unable to parse YAML" error, running `helm template --debug .` will show you the raw text of what's being generated, and sometimes it's obvious that something is incorrectly indented or a newline is missing.) – David Maze Nov 04 '21 at 11:08

2 Answers2

0

Turn the settings into a multiline string by using | in yaml. This way your json config isn't processed by helm.

customSetting:  
  arrayOfArrays: |
    [
      [ "someValue1", "someValue2" ],
      [ "anotherValue3", "anotherValue4" ]
    ]

Now your variable is a string and can be used without any modifiers

"CustomSetting": {
  "ArrayOfArrays": {{ .Values.customSetting.arrayOfArrays }}
}
Lukas Eichler
  • 5,689
  • 1
  • 24
  • 43
  • getting an execution error with your setup: *at <.Values.customSetting.arrayOfArrays>: can't evaluate field arrayOfArrays in type interface {}* – Hristo Nov 04 '21 at 08:54
  • @Hristo I adjusted the snippet. Can you try it again? – Lukas Eichler Nov 04 '21 at 09:03
  • now getting same error as I mentioned on the post: *unable to parse YAML: error converting YAML to JSON: yaml: line X: did not find expected key* – Hristo Nov 04 '21 at 09:14
  • If it is of any help I am using **vscode-helm v0.4.0** to lint the file and helm: **version.BuildInfo{Version:"v3.7.1", GitCommit:"1d11fcb5d3f3bf00dbe6fe31b8412839a96b3dc4", GitTreeState:"clean", GoVersion:"go1.16.9"}** – Hristo Nov 04 '21 at 09:28
0

I have had same issue, found following way that works for me:

  ArrayExample: |
    [
      [
        "asdf1",
        "asdf2"
      ],
      [
        "asdf3",
        "asdf4"
      ]
    ]

then the var is called via helm:"foo": {{ .Values.custom.ArrayExample | toPrettyJson }}

Best of luck

  • getting an execution error with our setup: *unable to parse YAML: error converting YAML to JSON: yaml: line X: did not find expected key* – Hristo Nov 04 '21 at 08:59