Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest way to convert JSON into BSON in .net world

I just started working on MongoDB. From my JavaScript client I am sending a JSON string to ASP.NET WEB API project. Is it possible to use this JSON string directly and save it into MongoDB? I also want to know whether this approach make sense ?

I am thinking of passing the JSON from client and on the server side read the string as

 [System.Web.Mvc.HttpPost]
    public dynamic SaveData([FromBody] string data)
    {

        System.Web.HttpContext.Current.Request.Form[0]
        return null;
    }
like image 226
SharpCoder Avatar asked Nov 19 '14 09:11

SharpCoder


People also ask

Can you convert BSON to JSON?

Converting a BSON Object to a JSON StringUse the asString method to convert the BSON document to an extended JSON string. See http://docs.mongodb.org/manual/reference/mongodb-extended-json/ for more information on extended JSON.

Why MongoDB employs BSON Binary JSON for its Storage & Networking in place of JSON?

Unlike systems that store JSON as string-encoded values, or binary-encoded blobs, MongoDB uses BSON to offer powerful indexing and querying features on top of the web's most popular data format.

What is BSON in C#?

BSON is a binary serialization format. " BSON" stands for "Binary JSON", but BSON and JSON are serialized very differently. BSON is "JSON-like", because objects are represented as name-value pairs, similar to JSON. Unlike JSON, numeric data types are stored as bytes, not strings.


1 Answers

Try this:

string json = "...";
BsonDocument.Parse(json);
like image 168
Philip Bergström Avatar answered Oct 25 '22 02:10

Philip Bergström