Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> it's a shame JSON doesn't support sum types "natively"

You can describe it using JSON Schema though[1], using "oneOf" and "const". Though I prefer the more explicit way of using "oneOf" combined with "required" to select one of a number of keys[2].

[1]: https://www.jsonschemavalidator.net/s/6SCuYNBe

[2]: https://www.jsonschemavalidator.net/s/tNnQmsTd



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: