-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
null
from Erlang to JSON and vice versa
#36
Comments
Just sharing some thoughts here, but I think there are 2 issues to be addressed:
|
The
So, if make sense to focus on point that the only null should be converted as is. At the same time it can be configurable over plugin mechanism which will add more flexible, so, by default type null will converted to atom null, by default undefined fields will be ignore as in JavaScript - and if somebody want to keep undefined fields, well he need to do it by using plugin config stuff. |
In https://github.com/zotonic/zotonic, we usually try to avoid |
Adding my 2c. For my use case:
The choice to use From my perspective:
So looking at it from an encoder view:
Being able to drop any properties with a null value is a feature that I would find useful as in my specific case, we do not send properties with This whole discussion has been around custom plugins to handle the cases, but I believe it's solved more simply as options for encode/decode. To cover the spectrum:
Ending my ramble.... |
Here's some thoughts... I agree with @vkatsuba's
which is consistent with what I discussed with you over Slack. This seems to be consistent with "proposal"
if the second argument was actually a default for the function call, and it also seems consistent with
|
Ok, so I'm planning to release a |
I've been working on this for a while, and last week, I decided to start from scratch and remove all the Euneus code. Now, Euneus is built on top of the new JSON module introduced in OTP 27. There are still things to do, documentation to improve, and the interface is not 100% defined. Feel free to test it out and give any suggestions. I'll close this issue soon when version 2 is released with the changes of the main branch. |
I'm closing this issue in favor of the v2.0 release. Thank you to all of you who contributed here! All of the comment was extremely valuable to this version. I've announced the version on the Erlang Forums. Thanks again, and feel free to continue contributing o/ |
There is a confusing thing about the null literal of JSON in Euneus (and probably in any other Erlang lib that encodes/decodes JSON).
Encode contains the
nulls
option and decode thenull_term
.When encoding,
nulls
is a list of Erlang terms considered to be thenull
literal of the JSON, e.g.:When decoding,
null_term
means what term to be considered as the null literal from JSON in Erlang, e.g.:Both options can be anything that you want.
Why this? Erlang and Elixir do not have a
null
term. What I see as a convention is the use of the atomundefined
for Erlang and:nil
for Elixir to representnull
terms. By default, Euneus considers the Erlang way, so the default for thenulls
option is[undefined]
and fornull_term
isundefined
. So,nulls
anddrop_nulls
plugin can sound strange because them doesn't have/ignore any null term by default.Due to this, I think we cannot use/consider the same Javascript approach, for example:
Using the
drop_nulls
Euneus plugin:@leonardb said:
@paulo-ferraz-oliveira said (translated from Portuguese):
@asabil said:
What I see is: there is no silver bullet.
Maybe some possibilities:
drop_nulls
from the Euneus plugins and let the user define what it considers to be removed from maps and proplists;drop_nulls
(probably not the best name in this case) must contain the terms to be ignored;Please help me by answering my question below:
What do you see as the best approach to consider null, undefined, nil, etc from Erlang to JSON and null from JSON to Erlang?
The text was updated successfully, but these errors were encountered: