I’m happy to announce the release of
Ppx_yojson_conv is a syntax extension that generates code for converting OCaml types to and from
Yojson.Safe.t, as defined in the yojson library. It has been written by Xueyuan Zhao, as part of his JaneStreet internship (summer 2019).
Ppx_yojson_conv is an alternative to
ppx_deriving_yojson based on ppxlib that leverages all the experience acquired with
ppx_sexp_conv over the years.
It tries to follow the serialization and parsing semantic of
ppx_deriving_yojson to ease the transition between the two derivers.
Some notable differences that motivated the creation of ppx_yojson_conv:
- It has better support for various ocaml construct (nonrec, polymorphic variants, non-regular types, …)
- It doesn’t rely on polymorphic comparison for code generated for “default” attributes.
- ppxlib will make sure all attributes have been consumed (allowing to spot typos)
- It generates different function names: t_of_yojson/yojson_of_t instead of of_yojson/to_yojson
- It supports types that reuse basic type names (string, int, unit, …)
Documentation is available at https://github.com/janestreet/ppx_yojson_conv
The package should be available in opam shortly.