News for hackers. Stuff that matters.
Re:A New Go API for JSON by brunoborges on Wednesday November 04, 2026 @04:45PM (#50371995)
> "JavaScript Object Notation (JSON) is a simple data interchange format [...]"

Clearly it isn't, otherwise every language would have sorted it out by... a long time ago.

Re:A New Go API for JSON by jayd16 on Wednesday November 04, 2026 @05:23PM (#50372329)
Ok so nothing is simple then?
Re:A New Go API for JSON by kccqzy on Wednesday November 04, 2026 @05:51PM (#50372575)
Some languages have a culture of doing things correctly and abiding strictly with the spec. These languages have indeed sorted it out years ago. Haskell for example. Any language that doesn’t have a special number type for JSON is imprecisely implementing the spec, because 1e10000000 is a perfectly valid JSON number that is beyond the typical IEEE754 implementation of floating point numbers; does your language handle that correctly? Haskell does.
Re:A New Go API for JSON by ncruces on Wednesday November 04, 2026 @06:09PM (#50372741)
Ironically Go has(d) json.Number which almost no one used, so it got dropped from v2: https://pkg.go.dev/encoding/json#Number

You can still use it though, and I built my tiny decimal library around it: https://github.com/ncruces/decimal

Re:A New Go API for JSON by layer8 on Wednesday November 04, 2026 @06:24PM (#50372863)
The spec (RFC 8259) leaves various leeways to implementations:

A JSON parser MAY accept non-JSON forms or extensions.

An implementation may set limits on the size of texts that it accepts. An implementation may set limits on the maximum depth of nesting. An implementation may set limits on the range and precision of numbers. An implementation may set limits on the length and character contents of strings.

At then there’s more vagaries with JSON schema.

Re:A New Go API for JSON by kccqzy on Wednesday November 04, 2026 @07:42PM (#50373491)
Yeah that’s what I mean by strictly. Does your implementation take shortcuts or does it hold itself to a higher standard and not do that?
Re:A New Go API for JSON by anthk on Wednesday November 04, 2026 @10:35PM (#50374814)
Which C standard? ANSI C? C99?
Re:A New Go API for JSON by kccqzy on Thursday November 05, 2026 @10:21AM (#50380225)
C99 and all subsequent versions.
Re:A New Go API for JSON by queenkjuul on Wednesday November 04, 2026 @10:43PM (#50374880)
I don't get your argument here. You say Haskell conforms strictly to the spec and that's a good thing, okay. But then if the C spec allows for truncated names, a compiler could strictly follow the spec and truncate names. So strictly following the spec is not in fact the whole story
Re:A New Go API for JSON by kccqzy on Wednesday November 04, 2026 @10:57PM (#50374987)
Yeah very sorry for the confusion. I should not have used the word strictly. I explained my definition of strictly in the above comment and it’s not really strictly in the dictionary sense. I apologize for my bad writing.
Re:A New Go API for JSON by layer8 on Thursday November 05, 2026 @07:19AM (#50378233)
The thing is this goes both ways. For example, JSON with duplicate keys is valid JSON, and the standard specifies two ways to handle them. To support all ways JSON is used, an implementation will have to provide for both ways, and decide which one to pick as the default. The stricter default on the parsing side is at the same time the less interoperable one. Same for numeric precision: seamlessly allowing higher precision on the generating side lowers interoperability, while accepting it on the parsing side increases interoperability (but also places higher demands on the consuming application). So what do you do? There is no easy and simple answer.
Re:A New Go API for JSON by yubblegum on Wednesday November 04, 2026 @06:59PM (#50373131)
Meet the "Simple Object Access Protocol": https://www.w3.org/TR/2000/NOTE-SOAP-20000508/
Re:A New Go API for JSON by ivanjermakov on Wednesday November 04, 2026 @07:05PM (#50373182)
Simple data format does not imply that API to work with it is easy to get right.
Re:A New Go API for JSON by DrBazza on Thursday November 05, 2026 @04:04AM (#50376906)
My company uses JSUN (/sarcasm) where O = object, and U = union.

Who knew the same object could have completely different definitions based on some flags?

Re:A New Go API for JSON by DanielHB on Thursday November 05, 2026 @05:31AM (#50377510)
I mean, it is better than the disaster that is CSV...
Re:A New Go API for JSON by thiht on Thursday November 05, 2026 @07:04AM (#50378151)
It IS a simple format. And you can make a parser yourself very easily. Doesn’t mean that it will be the fastest or most memory efficient. Don’t confuse format and implementation
Re:A New Go API for JSON by chabska on Thursday November 05, 2026 @09:44AM (#50379709)
The spec itself is simple, but different libraries are written that optimize for different things: parsing speed, streaming parsing, minimal memory usage, very very large data, distributed storage, etc.