Show Menu

Looking for an iOS Developer?

Submit your 30 day Job Listing for FREE

BSON is often referred as Binary JSON. BSON is the serialization of JSON-like objects that are binary encoded. Just like JSON, BSON also supports nested objects, arrays, strings, integers etc.

BSON supports some more data types, especially raw binary data. So we can consider BSON as a super-set of JSON.

BSON is designed to be fast to transport and fast to decode. The main features of BSON are:

  • Traversable
  • Light weight and
  • Efficient

Lets stop lecturing about BSON and move on to discussion regarding BSON decoding and integrating it to objC project.

We will make use of Martin Kou’s Bson Decode library for this purpose. Get the files along with the binary I created for your ease from

Add these files to your project:

BSON file project

Now add the required flags for these files:

BSON flag files

The binary we added will be already listed. We will have to change it to “Optional” to avoid the error when running in iPhone simulator.

BSON binary list

Thats it. You are all set to decode some BSON.

Import BSONCodec.h to where ever use need to decode BSON. With this wrapper, BSON decoding is as simple as a you alloc a new NSDictionary.

myDict =  [myBsonRecieved BSONValue];

Lets see what to do if we need to encode something to BSON.

Just like you decoded the BSON, simply call

bsonDataToSend = [myDict BSONEncode];

Hope that helps.

having issues?

We have a Questions and Answer section where you can ask your iOS Development questions to thousands of iOS Developers.

Ask Question

FREE Download!

Get your FREE Swift 2 Cheat Sheet and quick reference guide PDF download when you sign up to SwiftMonthly

Sharing is caring

If you enjoyed this tutorial, please help us and others by sharing using one of the social media buttons below.

Written by: