Click or drag to resize
Json.NET

Write as BSON

 

This sample writes a JObject to BSON using BsonWriter.

Sample
Usage
JObject o = new JObject
{
    { "name1", "value1" },
    { "name2", "value2" }
};

MemoryStream ms = new MemoryStream();
using (BsonWriter writer = new BsonWriter(ms))
{
    o.WriteTo(writer);
}

string data = Convert.ToBase64String(ms.ToArray());

Console.WriteLine(data);
// KQAAAAJuYW1lMQAHAAAAdmFsdWUxAAJuYW1lMgAHAAAAdmFsdWUyAAA=