BsonDocument bson = new { Name = "someone" }.ToBsonDocument();
string json = bson.ToJson(new JsonWriterSettings { OutputMode = JsonOutputMode.RelaxedExtendedJson });
json.Should().Be("{name:\"someone\"}");
The expected JSON output is {name:"someone"}, but the actual output contains spaces as { name : "someone" }.
I am concerned about the potential impact on bandwidth usage due to these unnecessary spaces in the JSON output. How I can ensure that the output matches the expected format without unnecessary spaces?
@Nima_Niazmand if bandwidth is a concern the .NET driver supports network compression which would greatly reduce any overhead introduced by this whitespace.
It’s already GZIP. Without spaces, it’s 13% smaller, give or take. Also, driver compression works between the database and the backend. The problem is in the backend and frontend.
Anyway, I wrote my own BSON stringify. Apparently, the C# driver dev team forgot to apply the open-close principle to the library.