Convert BSON to valid JSON

The BsonDocument.ToJson() method returns invalid JSON since ObjectID() and ISODate not valid JSON.

What is the best way to get valid JSON from a BSON arbitration document?

+7
c # mongodb bson mongodb-.net-driver
source share
1 answer

You can try something like this

 var document = new BsonDocument("_id", ObjectId.GenerateNewId()); var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }; // key part Console.WriteLine(document.ToJson(jsonWriterSettings)); 

More information https://groups.google.com/forum/#!topic/mongodb-user/fQc9EvsPc4k

+5
source share

All Articles