Azure / Azure/azure-powershell

PSCustomObject can't deserialize in json format

Open
#18,040 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

Reported from: https://github.com/Azure/bicep/discussions/6681

If we provide template parameter containing PSCustomObject type object. The deserialization of that object will be empty. The value should be there.To work around this issue, please try $data = $data | ConvertTo-Json | ConvertFrom-Json -AsHashTable.

### Issue script & Debug output

```PowerShell
# test.bicep
param dataArray array = []

output dataobj array = dataArray

# powershell script
$data = @{
messages = @(
[pscustomobject]@{message = '123'; count = 2 },
[pscustomobject]@{message = 'abc'; count = 1 }
)
}

New-AzResourceGroupDeployment -TemplateFile .\test.bicep -ResourceGroupName test -TemplateParameterObject $data -Verbose

DeploymentName : test
ResourceGroupName : test
ProvisioningState : Succeeded
Timestamp : 4/26/2022 4:24:26 AM
Mode : Incremental
TemplateLink :
Parameters :
Name Type Value
=============== ========================= ==========
dataArray Array [{},{},{},{}]

Outputs :
Name Type Value
=============== ========================= ==========
dataobj Array [{},{},{},{}]

DeploymentDebugLogLevel :
```

### Environment data

```PowerShell
N/A
```

### Module versions

```PowerShell
5.4.0 Az.Resources
```

### Error output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with test.bicep and the shown PowerShell script using Az.Resources 5.4.0, then trace New-AzResourceGroupDeployment handling of PSCustomObject template parameters. Done means the deployment and output preserve the message and count properties instead of producing empty objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.