I wrote some code to load a yaml file and do some work with the resulting data. I'm using the "gopkg.in/yaml.v2" package for it. This has been working fine for properly formatted YAML. However, today I discovered that a slightly misformatted YAML file is being happily loaded by this code, without throwing any error, but also making sort of odd decisions on what data to actually load, although seeing what it did I suppose that's debatable.
In my suspect yaml file, I have something like this: stuff: keys: - key1 - key2 - key3 Note the incorrect indentation for "key2" and "key3". When I load this with code like this: err = yaml.Unmarshal(configFile, &config) if err != nil { log.Fatalf("Failed to parse configuration file: %v", err) } This unexpectedly does NOT fail. However, it produces a "keys" list with only one entry, with the following value: key1 - key2 - key3 I can sort of see why it would make that decision. Is the lesson here that YAML is intended to be easily readable, but not easily writable? I see that there are some command-line tools for consistent formatting of YAML, but I need this done in code, but I think I'd rather just fail if the formatting is inconsistent. Is there any kind of a "strict yaml parser" that will notice things like this? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/3fa0e9cf-a05f-45e6-890e-66d28c1c0a17n%40googlegroups.com.