4 ms·
jsonnet[1] might suit your use-case better, it was created to do exactly that. [1]https://jsonnet.org https://jsonnet.org
by unrealhoang 4y ago
jsonnet[1] might suit your use-case better, it was created to do exactly that.
[1]https://jsonnet.org https://jsonnet.org
- Matheus28 4y agoNot OP. Looks interesting, but I'd bet that typescript's type system would enforce constraints a lot better
- whacked_new 4y agoin my experience, for things like static configs, jsonnet has been superior to TS for constraints, if you pair the configs with a json schema (also generated from jsonnet, of course). TS's types are easier to use at write-time, but json schema includes a lot of batteries that save a lot of time when you need them, but become annoying in TS, like patternProperties in dictionaries, length constraints in keys. Of course, there are situations like key1 XOR key2 where you will need custom logic one way or another, but given json schema's evolution over the years, I think it's pretty solid. An added benefit is that if you stay in json schemas, you're almost guaranteed a validator exists in $other_language, it _almost_ feels like a first-class construct everywhere.
- Matheus28 4y agoThat's a valid point. I think that TS might also lack constraints for object keys and values (like matching them against a regex). After thinking for a while, I think that json schema might be the best approach to it (possibly generated from jsonnet if complicated enough).
- whacked_new 4y agojsonnet is my go-to language for anything related to configuration, after having tried json, yaml, TS, edn, and tasting dhall and toml. It addresses all problems in the article and more. the composition model strikes a good balance between data extensibility / language expressiveness / ease of use. the generated json leads to easy-to-understand and portable data, and if you write jsonschemas from jsonnet, tools like json-schema-to-typescript [1] make it easy to import a consistent interface, and almost every language has a reasonably up-to-date validation library. [1] https://github.com/bcherny/json-schema-to-typescript https://github.com/bcherny/json-schema-to-typescript