To use JsonWriter() in the C# we have different ways , lets look frequently used namespaces,

  • using MongoDB.Bson.IO ;
  • using Newtonsoft.Json ;

For using using MongoDB.Bson.IO'   we should add official MongoDB dll to the reference of the solution, add the mentioned namespace. you will be ready to use JsonWriter() for your class.

For using using Newtonsoft.Json ' we should add JSON.NET dll to our project, then call the mentioned namepace to use the JsonWriter() in your class.

JsonWriter() will provide the efficient JSON text as a output without any whitespaces and JSON is ready to store in database.