-
Notifications
You must be signed in to change notification settings - Fork 67
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
EEP68 - JSON #59
EEP68 - JSON #59
Conversation
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
Co-authored-by: Magnus Henoch <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should NOT stack the accumulator for the user, and let the user handle that and also make the array_finish/1
and object_finish/1
return {Obj, NewAcc}.
As it is implemented it is not useful if I for example during parsing also want to count the
numbers of sharks in my array of aquariums.
I think that the Acc0 sent in is the one returned from decode/3 shows that the current proposal is strange.
I think I agree with @josevalim empty_array and empty_object,
from a user perspective it seems strange to handle empty objects separately, though
looking at the code I can understand why.
@dgud yes, you're correct. I think my immediate concern was the overhead of the extra tuples each time we finalise a value - it does really add up. Let me try some benchmarks to see how much of an overhead that would be |
I pushed an update that removes the |
When designing the API for logger filters we decided to not use a
Do you think the same reasons apply to json? If so, should the encoder/decoder types be The reason I started thinking about this is because I had a look at Jason and it supports a couple of different ways to escape strings (javascript, html, etc). The way to implement the same thing with EEP-68 json would be to implement an encoder callback for binary, but you would need to have different funs for each encoding type as you cannot pass any arguments to the encoder. |
@garazdawi How are the functions called then? Is is As to the various escape functions in Jason - they're purpose is actually questionable, and I didn't have a clear goal with them, other than replicating the API of the older library Poison. In particular the |
Co-authored-by: Lukas Larsson <[email protected]>
They are called as the first example, I.e. I only mentioned the string escaping as an example of what you could want to do with the custom encoder interface. I don’t see any reason to add it to this module. |
Would the suggested implementation for the JSON encoding/decoding be done in Erlang or eventually NIF-based? What is the benefit of having this functionality to be a part of the Erlang distribution? There are already multiple good open-source JSON libraries available, and possibly reinventing the wheel might not be worth the effort. Being an author of one of such libraries, I might be biased. :) |
@saleyn The code should be more trustworthy if it is done in Erlang and not NIF-based, when considering the code initially added and its potential changes in the future. Erlang/OTP already provides |
The proposed API for both encoding and decoding includes callbacks - since it's not possible to call back to Erlang from NIFs, this can't be implemented as a pure NIF. There's a pure Erlang implementation PR opened against the OTP erlang/otp#8111. While the open-source implementations are great - this proposed one has even better performance and a significantly more flexible interface. It outperforms all pure Erlang implementations that I know of, and most of the time even the NIF-based jiffy (I failed to compile the simdjsone project). It's possible to eventually have some subsets of the implementation as a NIF (e.g. string escaping), but this doesn't seem necessary at the moment. Having it in standard distribution also makes it possible to use JSON in simple escripts (greatly enhancing the utility of Erlang as a scripting language) and makes it easy to use JSON in fundamental tooling like build systems (e.g. producing metadata about project layout for other tools like language servers), or in other parts of OTP itslef. |
@michalmuskala My memory of testing jiffy in the past was that it became slower when using the dirty thread pool, though it had the possibility of blocking VM scheduler threads if the JSON being parsed was too large (when not using the dirty thread pool). Avoiding performance and reliability problems like that with a pure Erlang implementation will be best. |
I would like to submit this for your consideration: https://erlangforums.com/t/jsonpull-a-json-pull-parser-for-erlang/3306 While this can lead to verbose code, it opens up a system where anything can be built on top, whether that is simple functions like my construct_list or even different kinds of parsers, like the ones already implemented here. Additionally, it could lead to third party libraries built on a standard one that immediately parses into expected types. |
This EEP proposes adding a
json
module to the standard libraryRendered