Encoding undefined
Erlang's atom as null in JSON frame
#228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
undefined
atom in Erlang is used as the default value for unset record fields, missing process dictionary entries, or lack of data in most of all the built-in data structures. It is exactly the same concept as null for other modern programming languages (C#, Java, JavaScript), nill (Go, Ruby, Swift), or None (Python, Scala, Rust), etc.Whenever encoding such Erlang term containing undefines to the JSON with Jiffy (for instance as a response for some API query), the coder has to write a custom converter for it. It can be something such simple as:
or more complex whenever more nested data structures are passed into it.
To solve this inconvenience and let us all keep Erlang's world and its conventions separate from formatting data to the JSON, I propose introducing a custom
use_undefined
encoding option. Very similar touse_nil
, but convertsundefined
atoms to JSON's nulls in place instead of nils.