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?
You can store JSON documents in SQL Server or SQL Database and query JSON data as in a NoSQL database.
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.
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));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With