You can use the MongoDB driver for Java to store a BSON object, then convert that to a String
which you can then wrap with JSONObject.
For example, here's how I'll create a regular document:
BasicDBObject obj = new BasicDBObject();
obj.put("name", "Matt");
obj.put("date", new Date());
Then, to get a String
representation of the object, simply call:
String bsonString = obj.toString();
Wrap it with a JSONObject
and get the date attribute, which should return it in a BSON-compliant format.
JSONObject newObject = new JSONObject(bsonString);
System.out.println(newObject.get("date"));
The resulting output is something like:
{"$date":"2012-08-10T05:22:53.872Z"}