JSON alternatives for OCaml web front-end + back-ends?

JSON is ubiquitous & a bit of a lingua franca with fast serialization. However, JSON while being a bit bloated (can be saved on the wire by compression) also lacks a lot of valuable built-in types: maps, sets, dates, ADTs, etc. If using OCaml on both the front-end & back-end what alternatives are folks using to minimize loss of data type information …or is there such a performance gain to sticking JSON that any other encoding is just too slow? Are there XML, BSON, MessagePack, Avro, EDN or other users? Dhall or Nickel would cover a lot of the type+contractual information, but no parsers for the languages are available.

1 Like

I like and use CBOR (RFC 8949). There are a couple of implementations for OCaml: ygrek/ocaml-cbor, mattjbray/ocaml-decoders or openengiadina/ocaml-cborl.

2 Likes

You can also see the serialization part of:

1 Like

Atdgen has evolved to be quite advanced at handling OCaml/JSON interop, it seems to have support for quite a lot including variants.

I use ASN.1 when I can – you get opam install asn1-combinators and be done with it. If you’re keen on amount of data, you may like to look into how to implement packet encoding. But so far, der/ber has been sufficient for me. The wire data is not human-readable, but for me that’s a feature :slight_smile: – there’s lots of external tooling around, such as ASN.1 JavaScript decoder

1 Like