Return JSON from Azure Functions with Python

I was working on an Azure Function for an open source wildlife IoT project and came across a lack of documentation in docs.microsoft.com. I had successfully returned HTTP content from my Azure function, but wasn’t sure how to get it to return JSON so I could interpret it elsewhere. In this case I’m storing latitute (lat) and longitude (lon) and returning them in JSON content:

Here’s the block:

 #at the top      
 import json

 #to return
         return func.HttpResponse (
            json.dumps({
            'lat': lat,
            'lon': lon
 
            }) 
         )


Enjoy!

Nathan

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s