News for hackers. Stuff that matters.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by carom on Monday January 02, 2023 @06:44PM (#34225383)
Every time I go to use JSON it is great until I remember it cannot represent 64 bit integers.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by jayd16 on Monday January 02, 2023 @07:20PM (#34225717)
Huh? The json number spec does not specify a precision or size. Any limitation is from your parser.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by gabetax on Monday January 02, 2023 @08:24PM (#34226306)
This is a Javascript issue, not a JSON issue. The JSON spec doesn't apply any limits on the number type. ECMA-404 states:

> JSON is agnostic about the semantics of numbers. In any programming language, there can be a variety of number types of various capacities and complements, fixed or floating, binary or decimal. That can make interchange between different programming languages difficult. JSON instead offers only the representation of numbers that humans use: a sequence of digits. All programming languages know how to make sense of digit sequences even if they disagree on internal representations. That is enough to allow interchange.

It also explicitly excludes NaN encoding, which further distances itself from any coupling to IEEE floating point expectations.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by jillesvangurp on Tuesday January 03, 2023 @03:50AM (#34229338)
Yep, if you use e.g. Java's jackson, you can configure it easily to deserialize numbers as BigInteger or BigDecimal instances. Useful trick if you need it and it really works. You can have arbitrary precision numbers in Json. Of course this does challenge most other parsers out there.
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by vbezhenar on Monday January 02, 2023 @09:09PM (#34226651)
Use https://www.npmjs.com/package/json-bigint

I think that one day browser will support it natively.

Re:Ask HN: Why isn't JSON-RPC more widely adopted? by RedShift1 on Tuesday January 03, 2023 @03:55AM (#34229381)
In Javascript, when do you need to represent something larger than 2^53 anyway?
Re:Ask HN: Why isn't JSON-RPC more widely adopted? by skunkiferous on Tuesday January 03, 2023 @06:31AM (#34230249)
Same. We use 64-bit ints as "Entity IDs", and countless other stuff. Saying that it's a "parser problem" is not really helpful, bc many parsers refuse to support 64-bit ints, even if they could, bc compatibility with JavaScript is more important than 64-bit ints for them. For example: jsonnet