Azure Function receiving double encoded json body

Viewed 26

I have an Azure Function based on PowerShell running, amongst other functions, an orchestrator. I have been calling the function several times with a json body.

When testing today, the function complained about the body not containing the required parameters. Looking into the issue it turned out, that it could be solved by converting the body from json twice!

Code prior to fix:

$request = $Context.Input | ConvertFrom-json -AsHashtable

Write-Information "ServicePrincipal: $($request.ServicePrincipalName)"

Writes "ServicePrincipal: " as output

After fix:

$request = $Context.Input | ConvertFrom-json -AsHashtable
if ($($request.gettype().name) -eq 'String') {
    $request = $request | ConvertFrom-json -AsHashtable
    Write-Host $($request.gettype().name)
}
Write-Information "ServicePrincipal: $($request.ServicePrincipalName)"

Writes "HashTable" and "ServicePrincipal: myname@myorg.com" as output.

Why has the behavior of the body content suddenly changed?

0 Answers
Related