Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expecting property name enclosed in double quotes when passing JSON string to Azure CLI (from PowerShell)

To create diagnostic settings on an Azure Firewall I want to pass in logs and metrics settings.

I define these in 2 variables and then pass 'em into Azure CLI:

$logsSetting = "[{'category': 'AzureFirewallApplicationRule','enabled': true,'retentionPolicy': {'days': 0,'enabled': false}},{'category': 'AzureFirewallNetworkRule','enabled': true,'retentionPolicy': {'days': 0,'enabled': false}}]"
$metricsSetting = "[{'category': 'AllMetrics','enabled': true,'retentionPolicy': {'days': 0,'enabled': false},'timeGrain': null}]"

az monitor diagnostic-settings create --name $FW_NAME `
   --resource $FW_NAME -g $VNET_GROUP --resource-type Microsoft.Network/azureFirewalls `
   --resource-group $VNET_GROUP `
   --workspace $FW_NAME `
   --logs $logsSetting `
   --metrics $metricsSetting

Executing this I get Expecting property name enclosed in double quotes: line 1 column 3 (char 2).

I tried without success

  • changed from multiline string literal to single line (which caused another error)
  • replaced ' with "
like image 932
Kai Walter Avatar asked Mar 23 '20 18:03

Kai Walter


1 Answers

Adding --debug parameter to Azure CLI revealed, that single quotes are eliminated in a argument transformation process which seems to cause the error:

Alias Manager: Transformed args to ['monitor', ... '--logs', '[{category: AzureFirewallApplicationRule,enabled: true,retentionPolicy: {days: 0,enabled: false}},{category: AzureFirewallNetworkRule,enabled: true,retentionPolicy: {days: 0,enabled: false}}]', '--metrics', '[{category: AllMetrics,enabled: true,retentionPolicy: {days: 0,enabled: false},timeGrain: null}]', '--debug']

Solution: escaping the quotes with \" made it work:

$logsSetting = "[{'category': 'AzureFirewallApplicationRule','enabled': true,'retentionPolicy': {'days': 0,'enabled': false}},{'category': 'AzureFirewallNetworkRule','enabled': true,'retentionPolicy': {'days': 0,'enabled': false}}]".Replace("'",'\"')
$metricsSetting = "[{'category': 'AllMetrics','enabled': true,'retentionPolicy': {'days': 0,'enabled': false},'timeGrain': null}]".Replace("'",'\"')
like image 187
Kai Walter Avatar answered Nov 15 '22 04:11

Kai Walter