Which json decoding library are you using?

I see some libraries from bucklescript and bs-json, which rescript-lang.org vendored for now (?). I will do more homework soon.

I am curious to here what libraries people are using.

1 Like

Funny you noticed that. I’m vendoring it because it has some npm installation problems that I don’t feel like repeating because it’s so draining lol. The goal is to remove it today.

We intend that repo and its commits to be more exemplary of what we’d like to see in our community (in currently has some legacy stuff I’m cleaning up), so stay tuned and keep watching the diffs!

Tldr: just follow the recommendations at JSON | ReScript Language Manual.

I did something very similar by binding a specific type to js-yaml result in my case, but it’s just not safe enough for my use case. It’s frustrating having undefined propagate through the logic if there is a mismatch in types or field names, without even causing an exception if you render the value directly.

If you see an undefined value, you know it can only be possible in the externals. Swallowing it into a generic null helper wouldn’t have helped. option (and result) type is supposed to indicate intentionally nullable types, not to silence accidentally undefined values. They should indeed at least cause some exceptions, but consider that they didn’t because e.g. the rendering facility automatically accepted nulls under the hood without throwing like you wanted it to.

And nothing prevents you from having one raw type to parse into and one idiomatic type and do the validations during that raw-idiomatic conversion free-form, without any library’s arbitrary constraint. This is what we’ll do in the diffs you’re watching. I’ll show you in a subsequent diff.

We’re using @decco and I’m personally loving it.


Having a two phases of parsing seems like too much noise

I started using bs-json. I wish bs-json included wrapResult from bs-aeson. I am most excited about bs-decode and jzon, and might start using one of them later on.

1 Like

It’s already two phases since you’re first using the native JSON.parse. And yes I agree it’s not great. Every json library in this ecosystem does that and I wish we could just do one-shot parsing.

But then again, nobody uses json for speed, sooo…