3
votes

I am working on an Azure Function that runs on the CosmosDB trigger. Microsoft has created this example https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-cosmos-db-triggered-function which works out nicely concerning the trigger.

I am now asking myself how to parse the returned document in a smooth way. The data I get back from the trigger function is from the class Microsoft.Azure.Documents.Document (IReadOnlyList<Document> documents).

Any nice idea on how to parse those data into Json objects or comparable?

Thx!

1
you might already be able to do this out of the box by replacing <Document> with <YourClass>silent
unfortunately not... it only allows the <Document> class...p1ngu1n

1 Answers

4
votes

Document can be deserialized to any type you want, for example:

foreach (Document document in documents)
{
    MyClass myClass = JsonConvert.DeserializeObject<MyClass(document.ToString());
}

You can also read any of its properties:

foreach (Document document in documents)
{
    string myPropertyValue = document.GetPropertyValue<string>("myProperty);
}