I I quite like the approach of ppx_deriving_yojson, where you specify a type and add annotations how JSON should be deserialized from and also generates serializers to do the reverse. All this in a type-safe way which avoids the problem with the misordered fields in the record.
I could imagine something like this could be useful in Elm, considering that JSON in Elm is far more important than it is in OCaml, where this is implemented using two libraries and some macro.
Yeah, this is very similar to the golang alternative. Just tag the fields in a struct as json and specify an incoming json name, and you’re good to go. In my experience, it doesn’t handle up so well when you need to decode a complex type (for example, recursive data structures that have optional fields), but it’s a lot better than what Elm has now.
The alternative I suggested isn’t really a good alternative - it’s one that solves one particular problem of the JSON API which new users rarely think about. My point of this blog post was to hopefully kick start this conversation and get people suggesting and providing alternatives, because I have pushed for automatic decoders/encoders long enough alone :)