News for hackers. Stuff that matters.
Re:Typical: Data interchange with algebraic data types by magicalhippo on Monday May 22, 2023 @01:53AM (#36027891)
> 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

There are no comments on this comment yet.