Is Base64 Encoded BSON smaller then BSON?
No: with base64, 3 bytes of plaintext become 4 bytes of encoded text, therefore the result will always be larger, no matter what the data payload is. See also: http://en.wikipedia.org/wiki/Base64
Piskvor's right, base64-encoded-anything is longer than raw. You base64-encode something to get it down a channel with a limited character repertoire, not as a means of reducing size.
Perhaps the question should be: Is Base64-encoded BSON smaller then JSON?
If so then JSON-vs-BSON is very much dependent on the content. For example arbitrary floating point numbers like 1.2345678901234567
are more efficiently stored in 8 binary bytes in BSON than the JSON string digit version. But the more common numbers like, say, 1
, are much more efficiently stored as strings in JSON.
For string values, BSON loses 4 bytes for a length word, but gets some back for every "
and \
JSON has to escape, plus more in strings with control characters where JSON has to use a hex sequence. (Some JSON encoders also \u
-escape every non-ASCII character to ensure safe transmission regardless of character set.)
IMO: BSON does not have a big compactness advantage over JSON in general. Its strength lies more in simplicity of decoding in a low-level language, plus datatypes JavaScript doesn't have. It can have marginal advantages for binary strings and a few other cases; it's certainly worth checking for a particular workload. But it's telling that the examples in the BSON specification itself are considerably smaller in JSON.
As for base64-encoded BSON: the same, except 33% worse.