question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Runtime fails to serialize json into hashtable

See original GitHub issue

Repro steps

Provide the steps required to reproduce the problem:

  1. Create a powershell function with the following parameters image
  2. add an http trigger function with following code:
using namespace System.Net
param($Request, $TriggerMetadata)
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $Request.Body.GetType()
})
  1. call the function with something like this:
{"buildId":"id","sourceVersion":"version","scopes":["/subscriptions/fdbb6770-4977-44e9-9ee4-4cf0fcc1e6b3","/subscriptions/51c2c6a2-e6bd-492d-8a9d-0b02d6a325d8"],"certValue":"MIIDDjCCAfagAwIBAgIQFZlpQaNVZYpFor0BFa4zHzANBgkqhkiG9w0BAQUFADAaMRgwFgYDVQQDDA9zZWNvcHMtMDEwLWhhc2gwHhcNMjEwODEzMDc1MDQzWhcNMjEwODE0MTE1MDQzWjAaMRgwFgYDVQQDDA9zZWNvcHMtMDEwLWhhc2gwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDaZTnBjT+szkqvd4FZS2hm+oww9jVZZAxwBNhLLhbq+N7y9EgtiWVsdlFgmoKH3hBaZca1631hqGafNdRGHZJu8DTmnyzgpHZLitzlmq3n4G65yC2kr4r88VSJvJieoCdSmOLjdmkl5Nm2Cedvp7EIs/u5VmjFw6dtYI1pgRmJAECYsxsKhABRnsUua7i2gAqEQs/TMgMoUXNnZ9y7aEDoLWgN7WlvMoOi2gFDFIxYhGoEQXD+EOexawbRMS2kfvAG2dE/fotSruSAf4zIabD0KjMVsAxHZiaAJ2LDEf/wVDWMzZ8CLq3R3XD807qE9RRbshZ+TefHZhBO7j/y00OBAgMBAAGjUDBOMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwHQYDVR0OBBYEFHy8F1cMI0ajtKr5+aizJNeBLatXMA0GCSqGSIb3DQEBBQUAA4IBAQCvPpBv8Uz2loVd/VhcUQNuCcam14vl5AS/mW72A37MVqi5BOjDLfUFzkrAIUiPRZSwuy+4JQrwRCdIZidWpcQXILwGA2FwXE7P4K4TNAKru2EUgbHL1TMUM73+/Epn2Pj5VtA5zrYbmToNYkDp3juYPieGV//9A112rStFc1mAl+OziQb0YMv2X255ECOe+eliSODxzupzUs9VEHsYPHWJLPnufVsGrGRSEmpbu3dy+YsTbB6dtLZE2AqdTDPhbKJBvLb78FgGiDide4gcp4MhC1Rm9k2NYpNf/EDcPHcWRGvSZ+49JsZup9CWec/7EbZ5MrGJxHt2fpw19khAGyMw"}

Expected behavior

returns System.Collections.Hashtable

Actual behavior

returns System.String

Known workarounds

forcefully cast to an object with $Request.Body | ConvertFrom-Json

Related information

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#request-object

  • using powershell
  • works with a simpler json payload (ie: {"name": "please_work"})
  • json is valid (RFC 8259)
  • bindings:
{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "Request",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "Response"
    }
  ]
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Francisco-Gaminocommented, Sep 8, 2021

To close on this, to deserialize the body into a hashtable, the request should specify the Content-Type header to be ‘application/json’. We will update the docs to reflect this.

1reaction
Francisco-Gaminocommented, Sep 3, 2021

@4c74356b41 – I’ve created a separate issue to track the Durable activities scenario: Runtime fails to serialize json into hashtable for Durable activities.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Runtime fails to serialize json into hashtable for Durable ...
Repro steps Provide the steps required to reproduce the problem: Create a powershell function with the following parameters add an http ...
Read more >
Java Jackson Serialize JSON to HashTable
I am trying to serialize a list of JSON blobs and put certain keys into a HashTable during the serialization. Here is an...
Read more >
Efficient JSON serialization with Jackson and Java
The Jackson open source library for JSON works with many programming languages.
Read more >
Supported collection types in System.Text.Json
This article gives an overview of which collections are supported for serialization and deserialization. System.Text.Json.
Read more >
Everything you wanted to know about hashtables
Hashtables are really important in PowerShell so it's good to have a solid understanding of them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found