1

The encoding/json exposes a forgiving parser. Every not present property is simply set to its default value. Is there a better way to make a field required than using bulky switch statments and check every field for its default value? Another problem is that not all default types are nil. Is there another way to distinguish between than a not set field and e.g. 0 other than using pointers to be able to check against nil?

1 Answers1

0

You may look at what there is available to implement so-called "JSON schema validation".

You may start with this search which yields github.com/juju/gojsonschema among others; while I have no idea about its quality, it's used as part of Ubuntu's Juju cloud orchestration solution so I'd expect it to be battle tested. Still, caveat emptor.

kostix
  • 51,517
  • 14
  • 93
  • 176