Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it called BSON?

So BSON is JSON serialized right?

{"hello": "world"}"\x16\x00\x00\x00\x02hello\x00 \x06\x00\x00\x00world\x00\x00"

But why is it called Binary Json? What does binary stands for?

I always tend to associate binary with 10101010101. But the BSON serialization format above wasn't in 101010101010 form.

Could someone explain for me what the Binary here means so I understand why it's called Binary JSON?

like image 989
never_had_a_name Avatar asked Aug 24 '10 07:08

never_had_a_name


People also ask

Why does MongoDB use BSON rather than JSON?

BSON's binary structure encodes type and length information, which allows it to be traversed much more quickly compared to JSON. BSON adds some non-JSON-native data types, like dates and binary data, without which MongoDB would have been missing some valuable support.

Is BSON better than JSON?

BSON is also designed in a way that it has a comparatively faster encoding and decoding technique. For example, all those integers stored as 32-bit integers so that they are not parsed with them to and from the text. Therefore, it uses more space than JSON for smaller integers, but BSON is anyway much faster to parse.

Did MongoDB invent BSON?

BSON originated in 2009 at MongoDB. Several scalar data types are of specific interest to MongoDB and the format is used both as a data storage and network transfer format for the MongoDB database, but it can be used independently outside of MongoDB.

What is the difference between a JSON and BSON document?

Differences between JSON and BSON. It is a binary file format type. JSON contains some basic data types like string, numbers, Boolean, null. BSON contains some additional data types like date, timestamp, etc. Databases like AnyDB, redis, etc.


2 Answers

It's binary as opposed to text. Whereas JSON is human-readable text, BSON is binary data (just bytes). You could write it out as 1001010 etc, but it's more common to show each byte at a time (so \x16 is just hex 16, i.e. the decimal byte 22). Basically "binary" here is used to compare it with textual data, not to say that it's actually base 2 in particular.

This means that you can only use BSON in situations where you can transport arbitrary binary data. For example, if you wanted to embed BSON in an XML document (for whatever reason!) you'd have to base64 encode it first, because XML is a text-based representation.

like image 145
Jon Skeet Avatar answered Nov 15 '22 17:11

Jon Skeet


Binary is really a misnomer, since everything on your computer is "binary" at some level. Binary, when it comes to file or network stream formats, means not-easily-human-understandable. It also tends to be compact.

Examples of textual or "human readable" (human understandable) file and stream formats:

  • xml
  • xpm
  • js
  • http

Examples of "binary" file and stream formats:

  • jpeg
  • mp3
  • avi
  • dll
  • Quake (a videogame) network protocol

The thing of most note here is that human understandable formats need a lot less explanation if you simply crack them open and start reading. Binary file formats might need whole books to explain :)

A format isn't necessarily purely "binary" or purely human understandable, though. For example, you could probably understand a series of single digit numbers with no spaces, which represent an array of single digit numbers. You probably couldn't understand a series of 48 numbers (with no spaces), which represent x, y, and z values for 16 3d vertices, even though you can "read" them. Also, there is Skeet's example of encoded "binary" data, especially if it is embedded in a more human understandable format.

like image 27
Merlyn Morgan-Graham Avatar answered Nov 15 '22 17:11

Merlyn Morgan-Graham