what is the recommended way to decode a JSON in ReScript?
Do I have to use a library like bs-json or decco or is there a way to do it in pure ReScript?
As far as I know those two libraries are the best way to do it if you care about validation.
If you don’t care about validation of course you can use the method in that link you shared, or do lots of naughty things with Obj.magic (which of course can be very dangerous from a code correctness point of view!).
I personally use decco, because it is so extremely easy to setup (just add [@decco][@decco.decode] or [@decco.encode] above the type you want to decode to depending on your use).
[I’ve heard that decco can sometimes add extra code and be more heavy than bs-json, and since it is a ppx can slightly slow down your compile - just to list some of it’s downsides.]
Just for readability comparison with rescript-schema, which is on the right, and rescript-json documentation on the left. Unless you’re building for a Cloudflare Workers, in my opinion, this is the best way to decode/encode JSON and even more.
For the record, rescript-json-combinators is very similar to elm-json, while also taking advantage of being written in rescript to make it significantly safer and more convenient in some (quite common) scenarios, such as decoding records.
Compare this decoder to the one above, for example: