…is valid YAML and valid JSON. We have no way of knowing which, so we don’t even bother looking for the [ character at all when auto-detecting the format.
Adding a format option would work when you know the format, but it would be better if we could handle it automatically.
Checking for a [ to auto-select JSON falls down when:
TOML has a [ in a quoted key that appears before a = (fairly common that it’s the first character)
YAML has a [ before a : as noted above
YAML has a [ in a quoted key that appears before a : (unlikely)
CSV has a [ before the delimiter (mildly likely)
So I guess we’d have to add a format option.
This works great:
{{ $s := `
[
"35acd975-9708-4536-9aa6-2d81893070dd",
"755633be-0dd7-4a88-8bee-91f3742eeb5a"
]
`}}
{{ $data := "" }}
{{ with $s | resources.FromString "foo.json" }}
{{ with transform.Unmarshal . }}
{{ $data = . }}
{{ end }}
{{ end }}
{{ range $data }}
{{ . }}<br>
{{ end }}
Because were naming the resource “foo.json”, transform.Unmarshal sees the “json” extension and knows what to do. No ambiguity.