← Back to context

Comment by brunoborges

23 days ago

> "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.

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

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.

Some languages have a culture of doing things correctly and conforming strictly to 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 a half-assed implementation, because 1e1000 is a perfectly valid JSON number that is beyond the typical IEEE754 double precision floating point numbers; does your language handle that correctly? Haskell does. This is but a small example of a strong culture bias towards correctness.

  • The spec (RFC 8259) leaves significant leeway 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.

    Add to that things like duplicate keys being allowed by the spec. There’s a lot of implementation choices to decide on.

    And then things can get really complex with JSON Schema.

    • 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? Does it only use available memory as the ultimate limit?

      A lot of specs contain these optional limitations. The C standard allowed implementations to truncate variable names to 31 characters if they have external linkage and 63 if internal linkage. Would you be happy if your implementation actually does that? Of course not. Neither LLVM nor GCC does that. That’s because people writing compilers also hold themselves to a higher standard. Now imagine this kind of attitude being pervasive.

      5 replies →

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?