3 ms·
Show HN: TxJSON – An extension of JSON5 with rich inline type information
- voodooattack 3y agoThis is something I have been working on as part of a larger project where we use it for programmatic test generation. This extended syntax allows the inclusion of type information within a document. This means that after parsing, a user-defined deserializer can pick up the raw value and do anything with it (whatever it returns is included in the output of `parse`), and that a user-defined validator can allow or reject it with an error. Documentation (mainly for deserializers/validators) is currently sparse since I'm somewhat busy with a deadline, the tests have many examples though. I plan to expand on it later. Here is a glance at what it looks like: ``` { x: date "2001-01-01", // it can handle custom deserializers! y: 123n, // it can handle `BigInt` out of the box! z: /^I\sCAN\sPARSE\sREGEX$/im, // ...and also regular expressions! w: undefined, // ...and even `undefined`! } ``` There are more examples on GitHub!