Hacker News new | ask | show | jobs
by byroot 526 days ago
Yes, JSON as a format is very much under specified, a lot of these sorts of things are basically implementation defined.

In general libraries do what make sense in the context of their host language, or sometimes what makes sense in the context of JavaScript.

For ruby/json, I consider that if something can be rountriped, from Ruby to JSON and back, it should be, which means not reducing float precision, nor integer precision, e.g.

    >> JSON.generate(2**128)
    => "340282366920938463463374607431768211456"
But other libraries may consider that JSON implies JavaScript, hence the lack of big integer, so such number should be dumped as a JS decimal string or as a floating point number.

> I don't see anything in [...] specifying that Strict will force floating points to specific precision vs other implementations

Yes, and that's my problem with it. As you said, Oj is free to do so by the JSON spec, but I'd bet 99% of users don't know it does that, and some of them may have had data truncation in production without realizing it.

So in term of matching other libraries performance, If another library is significantly faster on a given benchmark, I treat it as a bug, unless it's the result of the alternative trading what I consider correctness for speed.