Return JSON from C# Azure function

Return JSON from C# Azure function

In this blog post I’ll build a simple C# Azure function that returns an object as JSON. That’s useful if you want to build a simple “API” or if you just want to return some information in a structured format. Such a function could read data from an on-premise environment and provide this data to a logic app, because it’s much easier to connect an Azure function to on-premise than a logic app.

Create a C# Azure Function

First step is to create a new C# function. I’ll use the HttpTriggerWithParameters-CSharp template and I’ll use the authorization level ‘Anonymous’ (that’s okay for this demo):

When the function is created, we can start to implement the logic, but before we jump into the code, we must include the package Newtonsoft.Json. As this package is a standard package and specially handled, it can be referenced by simply putting the following line at the beginning of the run.csx file:

That’s the whole magic. If we look at the output window of our Azure function, then it should show us the successful compilation and if we started, then also the information that the function started/stopped:

To call the function via an URL, we must get the URL from the function. Fortunately there is a button “Get function URL” which makes it easy:

If we call the URL with, then the function returns JSON content that we can reuse in our applications. I called it with my browser and that’s the output: