Like [this](https://github.com/kuenishi/meddatum/blob/master/src/hl7.erl#L111).

```erlang
encoder() ->
    jsonx:encoder([{weight_info, record_info(fields, weight_info)}],
                  [{ignore, [null]}]).

to_json(#weight_info{}=W) ->
    E = encoder(),
    case E(W) of
        Bin when is_binary(Bin) -> Bin;
        Other -> error(Other)
    end.
```

Maybe we can write a simple record<->JSON mapper with `lists:zip` .