What are the main differences between JSON and BSON formats?

20

I was reading an article on Internet , where it was commented on the format BSON ( Json Binário ), however I had some doubts about it:

  • What is BSON ?
  • For what reasons was it created?
  • Is there a big difference in performance between% w / w% w / w%?
  • Which languages support it?
  • When should I actually use it instead of JSON ?
asked by anonymous 29.12.2016 / 21:00

2 answers

13

There is no way to compare performance, this is very relative , it depends on the layer and in the end it will probably be JSON again (at run time), there might be a "cache" or whatever 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 make a difference. After all, both json and bson will have to do a parse to be used by internal application variables.

The format in BSON would look 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)

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

As I understand it, BSON is designed to store or transfer JSON in order to avoid loss of characters, for example. As the site has 3 goals :

  • Be light

    Keeping the overhead in minimal space is important for any form of data representation, especially when used over the network.

  • Transportable

    It was designed to be easily transportable.

  • 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 link

        
    29.12.2016 / 21:12
    10

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

    When storing data in 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 internally 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 of these attributes make data manipulation easier for the implementation of CRUD (create, read, update, and delete) data for MongoDB.

    BSON, as claimed by BSONSpec , is used by applications other than MongoDB.

        
    29.12.2016 / 21:09