-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Update json.nim #15420
Update json.nim #15420
Conversation
Add tuple and tuple array serialization. var js = %(id: 1, name:"a") var js2 = %[(id:1, name:"a"),(id:2, name:"b")] var js3= %[(1,"a"),(2,"b")] #Unnamed tuple, name is automatically replaced by fields0, fields2
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.
Hrm, I have a feeling there is a reason these don't exist.
Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
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 don't really see a point in this
JSON doesn't have tuples, it's not all that clear how to map it to JSON. Also, it breaks somebody's code. |
jsonutils.toJson is good enough:
|
This may not be the correct place to bring it up, but the documentation for one of the Lines 370 to 371 in 939702a
Based on that, I was led to believe that JSON serialization would work for tuples the way this PR handled them, but since that proc only accepts objects that isn't the case. @timotheecour has a good way to serialize a tuple to JSON, but I wonder if either the documentation should be updated to only say Construct JsonNode from objects. or if Nim should allow serializing tuples as a part of the json module directly.Please correct me if I am wrong about what I'm assuming the documentation means here, I just put down what I interpreted it as after initially reading it. EDIT: Also in 863848a it appears that the json module did have tuple serialization, and it was removed by f8e720f. That helps explain the documentation though. |
I don't know anymore, but some package relied on |
FWIW there are a few issues/pull requests that mention this specific issue. |
named tuples should serialize to a
that's either too vague or doesn't seem like an actual regression. If some package adds in their tests import sequtils, strutils, ...
doAssert not compiles(foo) it shouldn't be sufficient grounds to prevent adding a symbol I'd vote for reverting f8e720f unless there's some concrete arguments why this is bad. |
It is suggested that "json" and "jsonutils" should be merged to achieve a consistent user experience. |
But what about users like me who don't want "jsonutils"? |
modules are cheap, dependencies are not and cause issues with cyclic imports. the original design of jsonutils was specifically intended to avoid having to import "the world" (ie all collections), but this regressed in #15133 which I tried to oppose in #15133 (comment)
The design before that PR allowed users to use jsonutils as a lightweight dependency, so maybe we should go back to that design. |
We have an RFC for this we should follow, it relies on my unfinished |
Modules are cheap when they are not in the standard library. Just think about how easy it would be to change this behavior outside of stdlib. How many modules have you published outside the stdlib, @timotheecour ? |
Add tuple and tuple array serialization.
var js = %(id: 1, name:"a")
var js2 = %[(id:1, name:"a"),(id:2, name:"b")]
var js3= %[(1,"a"),(2,"b")] #Unnamed tuple, name is automatically replaced by fields0, fields2