Libbson provides routines for converting to and from the JSON format. In particular, it supports the MongoDB extended JSON format.
There are often times where you might want to convert a BSON document to JSON. It is convenient for debugging as well as an interchange format. To help with this, Libbson contains the function bson_as_json().
Converting back from JSON is also useful and common enough that we added bson_init_from_json() and bson_new_from_json().
The following example creates a new bson_t from the JSON string {"a":1}
.
Libbson provides bson_json_reader_t to allow for parsing a sequence of JSON documents into BSON. The interface is similar to bson_reader_t but expects the input to be in the MongoDB extended JSON format.
The following example reads BSON documents from stdin
and prints them to stdout
as JSON.