sile / jsone

Erlang JSON library
MIT License
291 stars 72 forks source link

Option to decode null to undefined #26

Closed Licenser closed 7 years ago

Licenser commented 7 years ago

With undefined_as_null there is a situation where the encoded and decoded data does not match at this point as null is always decoded as null. It would be nice if the decode took undefined_as_null as an option as well to mirror the behavior of the encoder.

pichi commented 7 years ago

jsone doesn't have to necessarily conform to matching encoded and decoded data requirement for every option and data combination. undefined_as_null is a good example of it.

1> X = [null, undefined], jsone:encode(X, [undefined_as_null]).
<<"[null,null]">>

There is not a way you could generaly decode [null,null] JSON to match X = [null, undefined].

Licenser commented 7 years ago

Yes mixed decoding can't work. However, it's not entirely unreasonable to approach it from a way of "if you use undefined you should stick with undefined" no one will expect an en/decoder to magically know which null was what before. Expecting to keep the same value for en-decoding as long as that information is available seems reasonable.