Live data from Hacker News

You're Using JSON, Why not MessagePack?

blog.andrewvc.com

21–30 of 66 posts

Re: You're Using JSON, Why not MessagePack?

#22

For the same reasons we are in the process of switching from Protocol Buffers back to JSON: * It does not support our languages. Is there a Ruby module with no C extension? A C# library? Lua? What about that really cool language coming out next week? What about C? * Even if it does, why have to deal with someone else's poor API design? JSON has a million parsers for everything, and if by chance you don't like any of…

> It does not support our languages. Is there a Ruby module with no C extension?

This first part was already addressed in another comment, but ...

> A C# library? Lua? What about that really cool language coming out next week? What about C?

... yes.

> It's not human-readable. Enough said.

"Enough said" is glib, but it doesn't seem obvious to me. The computer is the one using the data the vast majority of the time, not a human. I'd rather optimize for that, improve the user experience and reduce parsing overhead, and use protobuf --decode for my own debugging.

> It's smaller that JSON, sure, but is it smaller than gzipped JSON?

Is GZIP'd JSON smaller than GZIP'd protobuf? What is the decoding time of a GZIP'd JSON file vs a non-GZIPd protobuf file?

Regardless, all of these reasons seem to be more about making your life mildly easier (or at least more closely matching your preferences), and less about optimizing for CPU and bandwidth utilization of the client interface.

We just switched to protobuf because it allowed us to provide the best user experience by decreasing both parse time and transmission cost, AND we can auto-generate the serialization code, including validating the messages for correctness.

If anything, I'd choose to move to an even more rigorous message specification format, as having the validation done for us automatically keeps our client-side code very simple compared to the data extraction and type validation we have to write manually with JSON.

Re: You're Using JSON, Why not MessagePack?

#23
post #6

http://bsonspec.org/ is another such alternative.

Yes. The first thing I said when I saw this post was "How is this different than BSON?" Given that BSON is the basis of MongoDB's storage engine, I'm pretty confident in it and probably won't be moving over to MessagePack anytime soon.

bson messages are often larger than their json counterpart. The benefit of bson isn't size, but rather ease (on the cpu) of serializing and deserializing.

Re: You're Using JSON, Why not MessagePack?

#25
post #23
post #6

Earlier quoted context omitted.

Yes. The first thing I said when I saw this post was "How is this different than BSON?" Given that BSON is the basis of MongoDB's storage engine, I'm pretty confident in it and probably won't be moving over to MessagePack anytime soon.

bson messages are often larger than their json counterpart. The benefit of bson isn't size, but rather ease (on the cpu) of serializing and deserializing.

I agree in part. Most of the time JSON and BSON are very similar in size, and sometimes larger (due to length prefixes). But, size benefits do emerge when you need to store binary data inside the object. Instead of a base64 encoded string, the binary data can be stored directly.

Re: You're Using JSON, Why not MessagePack?

#26

Earlier quoted context omitted.

> Is there a Ruby module with no C extension? Why is the "with no C extension" part important to you?

This is important if you want to use JRuby.

Exactly! Also IronRuby. Or MRI on Windows for a lot of extensions, which just won't build there.

Re: You're Using JSON, Why not MessagePack?

#27

Because JSON is around twice as fast to encode/decode in Node, which is where I really need the performance. MessagePack is just slow, complicated, and unnecessary.

Citation needed, especially since the node-msgpack library docs say it's anywhere from 1.2-3X faster. https://github.com/pgriess/node-msgpack

Re: You're Using JSON, Why not MessagePack?

#29
I'm not using JSON or MessagePack because I need to send arbitrary binary data. I understand why people use JSON, and it has its domain (sending data to and from the browser), but in other situations I don't think it is a good protocol.

Another poster mentioned tnetstrings, those look interesting, however I am not sure how well those would handle binary data.

Re: You're Using JSON, Why not MessagePack?

#30
I'm certainly glad if MessagePack allows non-string keys in maps, as it apparently does (I've only read the spec so far, but not had a chance to try the code). This is a real pain in JSON.

My stock “basic data type” set comes mainly from Ruby these days. I wince a little at the lack of interned-symbol type, but it's possible to live without that. But what of string encodings? In a recent piece of code which I wouldn't mind replacing with MessagePack, I prefix strings with fixnum IANA encoding numbers. I suppose that's too much to ask in this context, though… ? How do other people deal with this—just force everything to UTF-8?

Post reply on HN