Search code examples
javajsonmongodbbson

Creating BSON object from JSON string


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?


Solution

  • The easiest way seems to be to use a JSON library to parse the JSON strings into a Map and then use the putAll method to put those values into a BSONObject.

    This answer shows how to use Jackson to parse a JSON string into a Map.