Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anyone figure out how to save a JSON string into a DocumentDB collection?

Am trying to make a quick and dirty NLog DocumentDB target but can't seem to be able to directly save JSON into a DocumentDB.

Using the C# library seems the document parameter of DocumentClient.CreateDocumentAsync() only wants a 'complex type' and I see no other methods that might take a JSON string.

Anybody else figured out how to save JSON directly?

like image 747
Mikee Avatar asked Mar 25 '15 18:03

Mikee


People also ask

Where should I store JSON?

You can store JSON documents in SQL Server or SQL Database and query JSON data as in a NoSQL database.

How do I save a JSON object in Python?

Method 2: Writing JSON to a file in Python using json.dump() Another way of writing JSON to a file is by using json. dump() method The JSON package has the “dump” function which directly writes the dictionary to a file in the form of JSON, without needing to convert it into an actual JSON object.


1 Answers

Here's a sample of how you can save a JSON string using DocumentDB using the C# SDK.

using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(@"{ a : 5, b: 6, c: 7 }"))) 
{
    await client.CreateDocumentAsync(collectionSelfLink,
        Document.LoadFrom<Document>(ms));
}
like image 151
Aravind Krishna R. Avatar answered Nov 04 '22 01:11

Aravind Krishna R.