Expand-AzTemplate errors when the provided json includes a property whose name is an empty string.
- Dominant language
- PowerShell
- Stars
- 468
- Forks
- 208
- PR merge metrics
- No merged PRs in 30d
Description
When using Azure bicep JSON import capability, the resulting ARM Template json can contain properties with empty values (Null string, Null Array). The current implementation that uses custom function Import-json fails with the following error: "_The provided JSON includes a property whose name is an empty string, this is only supported using the -AsHashTable switch._"
**Modifying the 'Import-Json.ps1' with the indicated switch parameter to the ConvertFrom-Json call resolves this issue.**
To simulate, create a sample json file and a bicep template:
_**testdata.json**_
`
{"test":"data","array":[],"array2":[1,2,3,4],"object":{},"string":null,"complex":{"name":"JohnDoe","email":null}}
`
**_test.bicep_**
`param name string!
var refData = loadJsonContent('testdata.json')
output name string = name ?? 'not provided'
output data object = refData`
Build the template:
`bicep build test.bicep`
Run the Arm Toolkit:
`Test-AzTemplate test.json`
Contributor guide
No contributing guide indexed for this repository
Research direction
Open Import-Json.ps1 and inspect the ConvertFrom-Json call. Reproduce the issue with the testdata.json and test.bicep examples, then run bicep build followed by Test-AzTemplate test.json; done means JSON containing null values and empty collections is accepted without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100