1

I am writing an Azure Function in Powershell that will be invoked from Azure Data Factory. ADF requires that Functions return a JObject. Can someone please supply (or point me to) a short, complete Function script that does this?

I tried adding this line to the starter template that Azure generates, but this is from C# and obviously not correct for Powershell.

return new OkObjectResult( new { StatusCode = $status, Body = $body });

Thanks!

2 Answers 2

1

Suppose you want powershell function return a json object, you could just use ConvertFrom-Json or ConvertTo-Json to convert between object and string.

Actually if your body is in json-format string, it will be OK.

$body = '{ "key1":"value1", "Key2":"value2" }'

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = $status
    Body = $body
})

enter image description here

If I misunderstand, please let me know, hope this could help you.

0
0

George Chen got me over the hump. My final solution is below. I verified that this works with Data Factory for both success and error responses.

$body = $('{ "functionReturnMsg":"'  + $msg + '" }')

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ 
    StatusCode = $status
    Body = $body   # Data Factory wants this in JSON
    })

The ADF documentation makes this sound more complicated than it really is.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.