-
Notifications
You must be signed in to change notification settings - Fork 23
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
json: add JsonKind, jsonKind (native json kinds) #353
Comments
When I want to get a
some convenience options should be added to work with Also, a common issue in json libraries is that they only support integers up to 53 bits due to a float being used as the underlying representation, after which they start losing precision - as a solution to this, some libraries output strings instead of numbers for anything larger than the float-compatible cutoff - it would be nice to perhaps set the jsonkind as well to handle quirks like this. |
the raw string is not available once you get a JsonNode and the original one is lost (eg we can't distinguish between different equivalent number representations). But you can already do case node.jsonKind
of JsonKind.Number:
let str = $node
what else?
IMO the proper way to solve this and related problems is to add rendering options, either adding more options to proc toString*(self: JsonNode, floatCutoff = false, indent = 2, multiline = true): string
let j = %(int64.high)
assert j.toString == "9223372036854775807"
assert j.toString(floatCutoff) == "\"9223372036854775807\"" # or maxBits = 53
assert j.toString(indent = 2) == ...
I don't think we need to set the jsonkind, since a json string is used as the interchange format (not the JsonNode structure itself), we just need rendering options. |
Is there a reason we can't add |
Someone needs to step up and make a BigInt for C target, theres already one for JS targets. |
unless I'm missing something, that's a separate problem; the point of this RFC is to introspect on the native json kind; (eg 1.2, 123, and 18446744073709551616 are both Number in json). |
Of general interest here might be the The key observation here is that parsing valid The other observation is that the specific desired mapping often depends on a more specific than json itself - the way for example We're considering splitting off |
I made very similar remarks when the problem was first reported but since then we focussed on a bugfix, I wasn't aware that it changed the behavior in a subtle way so the bugfix got backported. Mea culpa and the next time I'll ask Status for a review. |
proposal
add these to std/json:
rationale
isUnquoted
or adding isInteger (that would check kind and isUnquoted)links
The text was updated successfully, but these errors were encountered: