What are the main differences between JSON and BSON formats?

Asked

Viewed 4,047 times

21

I’ve been reading an article on Internet, where they commented on the format BSON(Json Binário), but I was left with some doubts about:

  • What is the BSON?
  • For what reasons he was created?
  • There is a big difference in performance between JSON x BSON?
  • Which languages support it?
  • When in fact I should use it instead of JSON?

2 answers

13


There’s no way to compare the performance, that is very relative, depends on the layer and at the end it will probably be JSON again (at runtime), it may be that there is a "cache" or something like that, of course in practice as you will have to first read and de-compile, but depending on the software used it may not even feel different. After all in the end so much json how much bson will have to parse to be used by internal variables of the application.

The format on BSON would be something like:

\x16\x00\x00\x00               // tamanho do documento
\x02                           // 0x02 = tipo String
hello\x00                      // nome do campo
\x06\x00\x00\x00world\x00      // valor do campo
\x00                           // 0x00 = type EOO (Final do objeto)

Amounts to this {"hello":"world"}.

From what I understand, BSON was created to store or transfer JSON in order to avoid loss of characters, for example. As the site has 3 objectives:

  1. Be light

    Keeping overhead to a minimum is important for any data representation format, especially when used on the network.

  2. Transportable

    It was designed to be easily transportable.

  3. Efficiency

    Data encoding for BSON and BSON decoding can be performed very quickly in most languages due to the use of C data types.

BSON is used by Mongodb, but there are a number of libs available at: http://bsonspec.org/implementations.html

11

BSON (Binary JSON) is an extension of JSON, and was initially performed by Mongodb, a Nosql Document DB, which uses it to perform data storage.

By storing data on Mongodb, you are already using BSON.

In addition to all JSON data (null, String, Number, Array, Object), BSON supports:

1) Minkey, Maxkey, Timestamp - types used domestically in Mongodb;

2) Bindata - byte array for binary data;

3) Objectid - unique identifier of a Mongodb record;

4) Date - date representation;

5) Regular expressions.

All these extra attributes make data handling easier for CRUD (create, read, update and delete) data implementation for Mongodb.

BSON, as stated by the Bsonspec, is used by applications other than Mongodb.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.