bsonparser is a library to help parsing BSON to JSON. It is written in C++ for performance purporses.
It parses all the common cases of BSON:
- Double
- UTF-8 string
- Embedded document
- Array
- Binary
- ObjectId
- Boolean
- UTC datetime
- Null
- 32-bit integer
- Timestamp
- 64-bit integer
To get the code, first clone this repository, then compile
the code using make
. The binary is generated in the bin folder
along with some sample files.
$ git clone https://github.com/mcornejo/bsonparser
$ cd bsonparser
$ make
There is a hardcoded test in the folder samples/
. To
test the library just run:
$ cd bin
$ ./bsonparser
Inside the samples/
folder there are other files to test the library which
are copied automatically
by the Makefile
.
$ ./bsonparser <file>
$ ./bsonparser test.bson
$ ./bsonparser mongodump.airpair.tags.bson
$ ./bsonparser clerks.bson
$ ./bsonparser identities.bson
$ ./bsonparser jobs.bson
The BSON
constructor takes as input a vector<char>
and it contains two methods:
-
BSON::Parse()
: This method parses the binary byte by byte. It does not iterate more than once over a BSON file once it is loaded into memory. It pushes each document found into avector<Document>
. -
BSON::Dump()
: This method prints the value of the BSON in JSON format in the terminal.
The repository contains all the Xcode project files to import it easily.
This library relies on the RapidJSON library
to store the parsed JSON. The version 1.1.0 of RapidJSON is along the code in the
include
folder.