Creating BSON object from JSON string

Maciek Sawicki picture Maciek Sawicki · Jun 25, 2010 · Viewed 96.8k times · Source

I have Java app that takes data from external app. Incoming JSONs are in Strings. I would like to parse that Strings and create BSON objects.

Unfortunate I can't find API for that in Java's BSON implementation.

Do I have use external parser for that like GSON?

Answer

yair picture yair · Oct 6, 2015

... And, since 3.0.0, you can:

import org.bson.Document;

final Document doc = new Document("myKey", "myValue");
final String jsonString = doc.toJson();
final Document doc = Document.parse(jsonString);

Official docs: