Comment by vbezhenar
3 years ago
I just checked YAML 1.2 and it seems that 1024 limit length on keys still in spec (https://yaml.org/spec/1.2.2/, ctrl+f, 1024). So any JSON with long keys is not compatible with YAML.
3 years ago
I just checked YAML 1.2 and it seems that 1024 limit length on keys still in spec (https://yaml.org/spec/1.2.2/, ctrl+f, 1024). So any JSON with long keys is not compatible with YAML.
The JSON specification [1] states:
> An implementation may set limits on the length and character contents of strings.
So this length limit is not a source of incompatibility with JSON.
[1] https://datatracker.ietf.org/doc/html/rfc7159#section-9
Wow! That makes it pretty hard to know you've generated useful JSON especially if your goal is to for cross-ecosystem communication.
To be fair, any JSON implentation is going to have a practical limit on the key size, it's just a bit more random and harder to figure out :)
If you mean limited by available memory, then sure but that does not apply just to key size. If you mean something else, could you elaborate?
Another reason to have a limit well below the computer's memory capacity is that one could find ill-formed documents in the wild, e.g., an unclosed quotation mark, causing the "rest' of a potentially large file to be read as a key, which can quickly snowball (imagine if you need to store the keys in a database, in a log, if your algorithms need to copy the keys, etc.)
I assume JSON implementations have a some limit on the key size (or on the whole document which limits the key size), hopefully far below the available memory.
2 replies →
I guess it is about different implementations of some not properly formalized parts of the JSON spec.
There was also an article here some time ago but I cannot find it right now.
1024 limit is for unquoted keys, which do not occur in JSON
Have a closer look. The 1024 limit in version 1.2 is only for implicit block mapping keys, not for flow style `{"foo": "bar"}`