Jsonm or yojson or?

to communicate with activitypub servers I need to read and write json. I need to pull data from various variants, so prbly manual ser/deser.

At the moment I use yojson e.g. at https://codeberg.org/mro/seppo/src/branch/develop/lib/as2.ml#L19 more by chance but deliberately.

I will produce a statically linked binary and care about small binary, small codebase, few features, few updates, to a lesser extent runtime ram and time. Have uutf etc. and will include cohttp I guess.

What can you recommend?

1 Like

ezjsonm is easy to use too

1 Like

Well, if you use Yojson already, the question is: why do you want to change? No JSON library is in constant development at this time since well, they do their thing and the JSON spec is essentially frozen in time, with no big changes coming up.

Yojson hasn’t changed significantly in many years, partly because it didn’t had to - it does what it needs to do and does it (reasonably) well. It recently dropped some dependencies and made sure to be OCaml 5.0 compatible so its impact on the dependency cone of your project is smaller.

The only things coming up in the Yojson world that I can think of would be the removal of custom extensions (which will not affect people who use regular JSON) and possibly JSON5 support - but given JSON5 is more a “nice to have” feature with overall rather little real-world use this quite low on the priorities.

3 Likes

Since you mention code size, the recent bump to 2.0.0 saw Yojson shed its dependencies (it has none now), so it reduces the final binary size vs 1.x. Meanwhile Jsonm depends on just uchar and uutf. If you use uutf anyway then I’d say both have a similar size overhead.

I haven’t used Jsonm though so I can’t speak to ease of use. Is run-time performance a factor at all for you? You might want to make a micro-benchmark comparing the two for typical message structures you’d be parsing and generating, to see how they differ in memory allocations and CPU time.

1 Like

@njb @Leonidas @VPhantom I’ll go forward with ezjsonm – it is somehow most appealing to me while yojson would be ok, too.