7

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?

1 Answer 1

11

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));
}
Sign up to request clarification or add additional context in comments.

2 Comments

I didn't think about streaming it.
I tried the above solution, It works for the simple objects but doesn't work for the complex objects. Is there any other way to do the same for complex objects?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.