DEV Community


Discussion on: Decoding JSON with Typescript

joanllenas profile image
Joan Llenas Masó Author

Never used Joi before but it looks much more powerful (and heavy).
This library is just a few bytes, although it has all the basic pieces you need to build more Joi-ish stuff (I guess).
Something you can do with that I don't see in the Joi docs is mapping over a decoded value. For instance:

type User = {
    id: number,
    name: string,
    dateOfBirth: Date

        id: JsonDecoder.number,
        name: JsonDecoder.string,
        dateOfBirth: => new Date(stringDate)),

Very useful.

Thanks for pointing that out Thijs.

0x80 profile image
Thijs Koerselman

Mapping seems useful indeed :)

I use Joi on the server so size is not an issue there. For the browser I use yup. Similar API but much smaller footprint.

Thread Thread
joanllenas profile image
Joan Llenas Masó Author

Interesting! smaller footprint but powerful too.
I might add an alternatives section in the docs.