I am trying to add a webtest in bicep and while deploying I get the following error :
ERROR: Failed to parse string as JSON:
[{Id: us-tx-sn1-azr},{Id: us-ca-sjc-azr},{Id: us-il-ch1-azr},{Id: us-va-ash-azr},{Id: us-fl-mia-edge}]
Error detail: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
My bicep for this looks like :
param testLocations array
resource availabilityTest 'Microsoft.Insights/webtests@2022-06-15' = {
name: testName
location: resourceGroup().location
kind: 'standard'
tags: {
'hidden-link:${appInsightsId}': 'Resource'
}
properties: {
Enabled: true
Frequency: testFrequency
Timeout: testTimeout
Kind: 'standard'
RetryEnabled: true
Locations: testLocations
Request: {
RequestUrl: testURL
HttpVerb: 'GET'
ParseDependentRequests: false
}
ValidationRules: {
ExpectedHttpStatusCode: testExpectedHttpStatusCode
IgnoreHttpStatusCode: false
SSLCheck: true
SSLCertRemainingLifetimeCheck: 7
ContentValidation: {
ContentMatch: testExpectedContent
IgnoreCase: true
PassIfTextFound: true
}
}
Name: testName
SyntheticMonitorId: testName
}
}
And I am passing in the locations variable like this :
[{"Id": "us-tx-sn1-azr"},{"Id": "us-ca-sjc-azr"},{"Id": "us-il-ch1-azr"},{"Id": "us-va-ash-azr"},{"Id": "us-fl-mia-edge"}]
I am guessing that the testLocations should be a string, and I have that set as an array right now. And perhaps the formatting of the locations array should be different? Any ideas welcome!
Bicep web test failing with ERROR: Failed to parse string as JSON:
In bicep, to pass the array formatted Json
input you need to use ''
single quotes and array declaration and definition should be done in the below format to avoid parsing errors.
param locations array = [
{
Id: 'us-tx-sn1-azr'
}
{
Id: 'us-ca-sjc-azr'
}
{
Id: 'us-il-ch1-azr'
}
{
Id: 'us-va-ash-azr'
}
{
Id: 'us-fl-mia-edge'
}
]
Reference blog by @Will Velida for more related details on the availability test code.
Complete Bicep code:
param appsname string = 'examplejahapp'
param webtest string = 'sampletestj'
param location string = 'WestEurope'
param locations array = [
{
Id: 'us-tx-sn1-azr'
}
{
Id: 'us-ca-sjc-azr'
}
{
Id: 'us-il-ch1-azr'
}
{
Id: 'us-va-ash-azr'
}
{
Id: 'us-fl-mia-edge'
}
]
resource Insights 'Microsoft.Insights/components@2020-02-02' = {
name: 'samapsjah123'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
}
}
resource appService 'Microsoft.Web/sites@2022-03-01' existing = {
name: appsname
}
resource availabilityTest 'Microsoft.Insights/webtests@2022-06-15' = {
name: webtest
location: location
kind: 'standard'
tags: {
'hidden-link:${Insights.id}': 'Resource'
}
properties: {
Enabled: true
Frequency: 100
Timeout: 60
Kind: 'standard'
RetryEnabled: true
Locations: locations
Request: {
RequestUrl: 'https://${appService.properties.defaultHostName}'
HttpVerb: 'GET'
ParseDependentRequests: false
}
ValidationRules: {
ExpectedHttpStatusCode: 200
SSLCheck: true
SSLCertRemainingLifetimeCheck: 7
}
Name: webtest
SyntheticMonitorId: webtest
}
}
Deployment succeeded: