30 ms·
I agree, IMHO is the biggest design fail and annoyance of JSON that it has no good way to contain binary data. The problem start with knowing the encoding (bas
by dathinab 7y ago
I agree, IMHO is the biggest design fail and annoyance of JSON that it has no good way to contain binary data.
The problem start with knowing the encoding (base64, for small sizes sometimes hex, for one or two bytes sometimes arrays with all there ambiguities).
Then that you can't easily differentiate between a string a bytearray anymore (through you often shouldn't need to).
Then that it becomes noticable bigger, which especially for large blobs is a problem
Then that you always have to scan over this now larger large chunk to know it's end.
(Inserted of just skipping ahead).
Then that you have to encoded/decide it which might require some additional annotations depending on serialization library and can imply other annoyances.
The later point can also in some languages lead to you accidentally using a base64 string as bytes or the other way around.
Well I guess that was enough ranting ;=)
- nine_k 7y agoIf efficiency and compactness are your problem, JSON is not the best idea anyway, look at protobufs and the ilk. JSON works where you need simplicity on the verge of being dumb, and human-readability.
- SlowRobotAhead 7y agoJSON human readable is extremely nice. FWIW, I’ve found some binary formats like CBOR and MsgPack to be so almost human readable as binary when you are even slightly familiar with the format, or just convert almost instantly to readable JSON. When I was developing a three component system, protos were not working for me. Too many schema changes and implementation differences to make the reduced binary size worth it. This was partly because the best protobuffer implementation in C (nanoPB) is just the hobby project of some dude, but mostly because coordinating schemas was annoying.
- tln 7y agoOn the contrary, adding binary would have been terrible. JSON is great because it is simple! Have you tried BSON or Protobufs to solve your annoyances? How did it go?
- SlowRobotAhead 7y agoProtobuffs require sharing of a schema, then code generation for each language. Not ideal imo unless you really need the speed and the protos can be shared ahead of time. Outside of Mongo, I haven’t seen BSON used anywhere. CBOR however, is up and coming. Starting to look like it may be a first class citizen in AWS someday. On the IoT side they are already preferring it over JSON for Device Defender.