Forum Discussion
tech4life2023
Jun 27, 2023Copper Contributor
Using conditional statement in a json
I am attempting to do conditional statement inside a .json file. I am finding that when a condition is met, the other conditions are ignored. It will only look a the first condition in my file whethe...
Kidd_Ip
Aug 21, 2025MVP
Take this to consolidate them into one resource and use conditional logic inside the properties block:
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2020-08-01",
"name": "[concat(parameters('virtualNetworkName'), '/', parameters('subnetName'))]",
"dependsOn": [],
"properties": {
"addressPrefix": "[parameters('subnetAddress')]",
"networkSecurityGroup": "[if(equals(parameters('networkSecurityGroupID'), 'N/A'), json('null'), json(concat('{\"id\": \"', parameters('networkSecurityGroupID'), '\"}')))]",
"routeTable": "[if(equals(parameters('routeTableID'), 'N/A'), json('null'), json(concat('{\"id\": \"', parameters('routeTableID'), '\"}')))]",
"serviceEndpoints": [],
"delegations": [],
"privateEndpointNetworkPolicies": "Enabled",
"privateLinkServiceNetworkPolicies": "Enabled"
}
}