Home  /  Blog  /  Documentation  /  Code Generator   /  Settings  /  BSon Serialization

BSon

Introduction

BSON simply stands for “Binary JSON,” and that’s exactly what it was invented to be. BSON’s binary structure encodes type and length information, which allows it to be parsed much more quickly.

JSON and BSON are close cousins, as their nearly identical names imply, but you wouldn’t know it by looking at them side-by-side. JSON, or JavaScript Object Notation, is the wildly popular standard for data interchange on the web, on which BSON (Binary JSON) is based.

BSON simply stands for "Binary JSON", and that is exactly what it was invented to be. BSON's binary structure encodes type and length information, which allows for much faster parsing.

With xsd2code++ producing JSON or BSON represents exactly the same steps. The only thing to consider is the choice of the serializer in the JSonSerializer or BSonSerializer options. The steps to follow are described in the page dedicated to JSON serialization.

Example

A document such as {"hello":"world"} will be stored as:


Bson:
\x16\x00\x00\x00 // total document size
\x02 // 0x02 = type String
hello\x00 // field name
\x06\x00\x00\x00world\x00 // field value (size of value, value, null terminator)
\x00 // 0x00 = type EOO ('end of object')

JSON vs BSON

JSON BSON
Encoding
UTF-8 String
Binary
Readability
Human and Machine
Machine Only
Data Support
String, Boolean, Number, Array
String, Boolean, Number (Integer, Float, Long, Decimal128...), Array, Date, Raw Binary

How to serialize in BSon format

To serialize to BSon format, it is exactly the same option as for JSON with the only difference being that the DefaultSerializer must be set to BSonSerializer.
Here is the code which will be generated in your classes or in a base class according to your options :

Terms & privacy

Terms of uses · Privacy policy

Contact

CodeNGine Technologies SIRET: 85257252800010, VAT : FR 62852572528
codengine.technologies@xsd2code.com

About the company

CodeNGine Technologies is software company based in the South of France that provides an advanced productivity code generation tool to developers using XML and JSON


Copyright © 2021 CodeNGine Technologies