Skip to content

Latest commit

 

History

History
2315 lines (1796 loc) · 70.6 KB

resource-group-template-functions-string.md

File metadata and controls

2315 lines (1796 loc) · 70.6 KB
title description services documentationcenter author manager editor ms.assetid ms.service ms.devlang ms.topic ms.tgt_pltfrm ms.workload ms.date ms.author
Azure Resource Manager template functions - string | Microsoft Docs
Describes the functions to use in an Azure Resource Manager template to work with strings.
azure-resource-manager
na
tfitzmac
timlt
tysonn
azure-resource-manager
na
article
na
na
09/05/2017
tomfitz

String functions for Azure Resource Manager templates

Resource Manager provides the following functions for working with strings:

base64(inputString)

Returns the base64 representation of the input string.

Parameters

Parameter Required Type Description
inputString Yes string The value to return as a base64 representation.

Return value

A string containing the base64 representation.

Examples

The following example template shows how to use the base64 function.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "stringData": {
            "type": "string",
            "defaultValue": "one, two, three"
        },
        "jsonFormattedData": {
            "type": "string",
            "defaultValue": "{'one': 'a', 'two': 'b'}"
        }
    },
    "variables": {
        "base64String": "[base64(parameters('stringData'))]",
        "base64Object": "[base64(parameters('jsonFormattedData'))]"
    },
    "resources": [
    ],
    "outputs": {
        "base64Output": {
            "type": "string",
            "value": "[variables('base64String')]"
        },
        "toStringOutput": {
            "type": "string",
            "value": "[base64ToString(variables('base64String'))]"
        },
        "toJsonOutput": {
            "type": "object",
            "value": "[base64ToJson(variables('base64Object'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
base64Output String b25lLCB0d28sIHRocmVl
toStringOutput String one, two, three
toJsonOutput Object {"one": "a", "two": "b"}

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/base64.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/base64.json

base64tojson

Converts a base64 representation to a JSON object.

Parameters

Parameter Required Type Description
base64Value Yes string The base64 representation to convert to a JSON object.

Return value

A JSON object.

Examples

The following example template uses the base64ToJson function to convert a base64 value:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "stringData": {
            "type": "string",
            "defaultValue": "one, two, three"
        },
        "jsonFormattedData": {
            "type": "string",
            "defaultValue": "{'one': 'a', 'two': 'b'}"
        }
    },
    "variables": {
        "base64String": "[base64(parameters('stringData'))]",
        "base64Object": "[base64(parameters('jsonFormattedData'))]"
    },
    "resources": [
    ],
    "outputs": {
        "base64Output": {
            "type": "string",
            "value": "[variables('base64String')]"
        },
        "toStringOutput": {
            "type": "string",
            "value": "[base64ToString(variables('base64String'))]"
        },
        "toJsonOutput": {
            "type": "object",
            "value": "[base64ToJson(variables('base64Object'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
base64Output String b25lLCB0d28sIHRocmVl
toStringOutput String one, two, three
toJsonOutput Object {"one": "a", "two": "b"}

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/base64.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/base64.json

base64ToString(base64Value)

Converts a base64 representation to a string.

Parameters

Parameter Required Type Description
base64Value Yes string The base64 representation to convert to a string.

Return value

A string of the converted base64 value.

Examples

The following example template uses the base64ToString function to convert a base64 value:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "stringData": {
            "type": "string",
            "defaultValue": "one, two, three"
        },
        "jsonFormattedData": {
            "type": "string",
            "defaultValue": "{'one': 'a', 'two': 'b'}"
        }
    },
    "variables": {
        "base64String": "[base64(parameters('stringData'))]",
        "base64Object": "[base64(parameters('jsonFormattedData'))]"
    },
    "resources": [
    ],
    "outputs": {
        "base64Output": {
            "type": "string",
            "value": "[variables('base64String')]"
        },
        "toStringOutput": {
            "type": "string",
            "value": "[base64ToString(variables('base64String'))]"
        },
        "toJsonOutput": {
            "type": "object",
            "value": "[base64ToJson(variables('base64Object'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
base64Output String b25lLCB0d28sIHRocmVl
toStringOutput String one, two, three
toJsonOutput Object {"one": "a", "two": "b"}

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/base64.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/base64.json

concat (arg1, arg2, arg3, ...)

Combines multiple string values and returns the concatenated string, or combines multiple arrays and returns the concatenated array.

Parameters

Parameter Required Type Description
arg1 Yes string or array The first value for concatenation.
additional arguments No string Additional values in sequential order for concatenation.

Return value

A string or array of concatenated values.

Examples

The following example template shows how to combine two string values and return a concatenated string.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "prefix": {
            "type": "string",
            "defaultValue": "prefix"
        }
    },
    "resources": [],
    "outputs": {
        "concatOutput": {
            "value": "[concat(parameters('prefix'), '-', uniqueString(resourceGroup().id))]",
            "type" : "string"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
concatOutput String prefix-5yj4yjf5mbg72

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/concat-string.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/concat-string.json

The following example template shows how to combine two arrays.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": { 
        "firstArray": { 
            "type": "array", 
            "defaultValue": [ 
                "1-1", 
                "1-2", 
                "1-3" 
            ] 
        },
        "secondArray": {
            "type": "array", 
            "defaultValue": [ 
                "2-1", 
                "2-2",
                "2-3" 
            ] 
        }
    },
    "resources": [
    ],
    "outputs": {
        "return": {
            "type": "array",
            "value": "[concat(parameters('firstArray'), parameters('secondArray'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
return Array ["1-1", "1-2", "1-3", "2-1", "2-2", "2-3"]

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/concat-array.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/concat-array.json

contains (container, itemToFind)

Checks whether an array contains a value, an object contains a key, or a string contains a substring.

Parameters

Parameter Required Type Description
container Yes array, object, or string The value that contains the value to find.
itemToFind Yes string or int The value to find.

Return value

True if the item is found; otherwise, False.

Examples

The following example template shows how to use contains with different types:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "stringToTest": {
            "type": "string",
            "defaultValue": "OneTwoThree"
        },
        "objectToTest": {
            "type": "object",
            "defaultValue": {"one": "a", "two": "b", "three": "c"}
        },
        "arrayToTest": {
            "type": "array",
            "defaultValue": ["one", "two", "three"]
        }
    },
    "resources": [
    ],
    "outputs": {
        "stringTrue": {
            "type": "bool",
            "value": "[contains(parameters('stringToTest'), 'e')]"
        },
        "stringFalse": {
            "type": "bool",
            "value": "[contains(parameters('stringToTest'), 'z')]"
        },
        "objectTrue": {
            "type": "bool",
            "value": "[contains(parameters('objectToTest'), 'one')]"
        },
        "objectFalse": {
            "type": "bool",
            "value": "[contains(parameters('objectToTest'), 'a')]"
        },
        "arrayTrue": {
            "type": "bool",
            "value": "[contains(parameters('arrayToTest'), 'three')]"
        },
        "arrayFalse": {
            "type": "bool",
            "value": "[contains(parameters('arrayToTest'), 'four')]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
stringTrue Bool True
stringFalse Bool False
objectTrue Bool True
objectFalse Bool False
arrayTrue Bool True
arrayFalse Bool False

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/contains.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/contains.json

dataUri(stringToConvert)

Converts a value to a data URI.

Parameters

Parameter Required Type Description
stringToConvert Yes string The value to convert to a data URI.

Return value

A string formatted as a data URI.

Examples

The following example template converts a value to a data URI, and converts a data URI to a string:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "stringToTest": {
            "type": "string",
            "defaultValue": "Hello"
        },
        "dataFormattedString": {
            "type": "string",
            "defaultValue": "data:;base64,SGVsbG8sIFdvcmxkIQ=="
        }
    },
    "resources": [],
    "outputs": {
        "dataUriOutput": {
            "value": "[dataUri(parameters('stringToTest'))]",
            "type" : "string"
        },
        "toStringOutput": {
            "type": "string",
            "value": "[dataUriToString(parameters('dataFormattedString'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
dataUriOutput String data:text/plain;charset=utf8;base64,SGVsbG8=
toStringOutput String Hello, World!

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/datauri.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/datauri.json

dataUriToString(dataUriToConvert)

Converts a data URI formatted value to a string.

Parameters

Parameter Required Type Description
dataUriToConvert Yes string The data URI value to convert.

Return value

A string containing the converted value.

Examples

The following example template converts a value to a data URI, and converts a data URI to a string:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "stringToTest": {
            "type": "string",
            "defaultValue": "Hello"
        },
        "dataFormattedString": {
            "type": "string",
            "defaultValue": "data:;base64,SGVsbG8sIFdvcmxkIQ=="
        }
    },
    "resources": [],
    "outputs": {
        "dataUriOutput": {
            "value": "[dataUri(parameters('stringToTest'))]",
            "type" : "string"
        },
        "toStringOutput": {
            "type": "string",
            "value": "[dataUriToString(parameters('dataFormattedString'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
dataUriOutput String data:text/plain;charset=utf8;base64,SGVsbG8=
toStringOutput String Hello, World!

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/datauri.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/datauri.json

empty(itemToTest)

Determines if an array, object, or string is empty.

Parameters

Parameter Required Type Description
itemToTest Yes array, object, or string The value to check if it is empty.

Return value

Returns True if the value is empty; otherwise, False.

Examples

The following example template checks whether an array, object, and string are empty.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "testArray": {
            "type": "array",
            "defaultValue": []
        },
        "testObject": {
            "type": "object",
            "defaultValue": {}
        },
        "testString": {
            "type": "string",
            "defaultValue": ""
        }
    },
    "resources": [
    ],
    "outputs": {
        "arrayEmpty": {
            "type": "bool",
            "value": "[empty(parameters('testArray'))]"
        },
        "objectEmpty": {
            "type": "bool",
            "value": "[empty(parameters('testObject'))]"
        },
        "stringEmpty": {
            "type": "bool",
            "value": "[empty(parameters('testString'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
arrayEmpty Bool True
objectEmpty Bool True
stringEmpty Bool True

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/empty.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/empty.json

endsWith(stringToSearch, stringToFind)

Determines whether a string ends with a value. The comparison is case-insensitive.

Parameters

Parameter Required Type Description
stringToSearch Yes string The value that contains the item to find.
stringToFind Yes string The value to find.

Return value

True if the last character or characters of the string match the value; otherwise, False.

Examples

The following example template shows how to use the startsWith and endsWith functions:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [],
    "outputs": {
        "startsTrue": {
            "value": "[startsWith('abcdef', 'ab')]",
            "type" : "bool"
        },
        "startsCapTrue": {
            "value": "[startsWith('abcdef', 'A')]",
            "type" : "bool"
        },
        "startsFalse": {
            "value": "[startsWith('abcdef', 'e')]",
            "type" : "bool"
        },
        "endsTrue": {
            "value": "[endsWith('abcdef', 'ef')]",
            "type" : "bool"
        },
        "endsCapTrue": {
            "value": "[endsWith('abcdef', 'F')]",
            "type" : "bool"
        },
        "endsFalse": {
            "value": "[endsWith('abcdef', 'e')]",
            "type" : "bool"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
startsTrue Bool True
startsCapTrue Bool True
startsFalse Bool False
endsTrue Bool True
endsCapTrue Bool True
endsFalse Bool False

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/startsendswith.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/startsendswith.json

first(arg1)

Returns the first character of the string, or first element of the array.

Parameters

Parameter Required Type Description
arg1 Yes array or string The value to retrieve the first element or character.

Return value

A string of the first character, or the type (string, int, array, or object) of the first element in an array.

Examples

The following example template shows how to use the first function with an array and string.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "arrayToTest": {
            "type": "array",
            "defaultValue": ["one", "two", "three"]
        }
    },
    "resources": [
    ],
    "outputs": {
        "arrayOutput": {
            "type": "string",
            "value": "[first(parameters('arrayToTest'))]"
        },
        "stringOutput": {
            "type": "string",
            "value": "[first('One Two Three')]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
arrayOutput String one
stringOutput String O

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/first.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/first.json

guid

guid (baseString, ...)

Creates a value in the format of a globally unique identifier based on the values provided as parameters.

Parameters

Parameter Required Type Description
baseString Yes string The value used in the hash function to create the GUID.
additional parameters as needed No string You can add as many strings as needed to create the value that specifies the level of uniqueness.

Remarks

This function is helpful when you need to create a value in the format of a globally unique identifier. You provide parameter values that limit the scope of uniqueness for the result. You can specify whether the name is unique down to subscription, resource group, or deployment.

The returned value is not a random string, but rather the result of a hash function. The returned value is 36 characters long. It is not globally unique.

The following examples show how to use guid to create a unique value for commonly used levels.

Unique scoped to subscription

"[guid(subscription().subscriptionId)]"

Unique scoped to resource group

"[guid(resourceGroup().id)]"

Unique scoped to deployment for a resource group

"[guid(resourceGroup().id, deployment().name)]"

Return value

A string containing 36 characters in the format of a globally unique identifier.

Examples

The following example template returns results from guid:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "variables": {},
    "resources": [],
    "outputs": {
        "guidPerSubscription": {
            "value": "[guid(subscription().subscriptionId)]",
            "type": "string"
        },
        "guidPerResourceGroup": {
            "value": "[guid(resourceGroup().id)]",
            "type": "string"
        },
        "guidPerDeployment": {
            "value": "[guid(resourceGroup().id, deployment().name)]",
            "type": "string"
        }
    }
}

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/guid.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/guid.json

indexOf(stringToSearch, stringToFind)

Returns the first position of a value within a string. The comparison is case-insensitive.

Parameters

Parameter Required Type Description
stringToSearch Yes string The value that contains the item to find.
stringToFind Yes string The value to find.

Return value

An integer that represents the position of the item to find. The value is zero-based. If the item is not found, -1 is returned.

Examples

The following example template shows how to use the indexOf and lastIndexOf functions:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [],
    "outputs": {
        "firstT": {
            "value": "[indexOf('test', 't')]",
            "type" : "int"
        },
        "lastT": {
            "value": "[lastIndexOf('test', 't')]",
            "type" : "int"
        },
        "firstString": {
            "value": "[indexOf('abcdef', 'CD')]",
            "type" : "int"
        },
        "lastString": {
            "value": "[lastIndexOf('abcdef', 'AB')]",
            "type" : "int"
        },
        "notFound": {
            "value": "[indexOf('abcdef', 'z')]",
            "type" : "int"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
firstT Int 0
lastT Int 3
firstString Int 2
lastString Int 0
notFound Int -1

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/indexof.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/indexof.json

last (arg1)

Returns last character of the string, or the last element of the array.

Parameters

Parameter Required Type Description
arg1 Yes array or string The value to retrieve the last element or character.

Return value

A string of the last character, or the type (string, int, array, or object) of the last element in an array.

Examples

The following example template shows how to use the last function with an array and string.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "arrayToTest": {
            "type": "array",
            "defaultValue": ["one", "two", "three"]
        }
    },
    "resources": [
    ],
    "outputs": {
        "arrayOutput": {
            "type": "string",
            "value": "[last(parameters('arrayToTest'))]"
        },
        "stringOutput": {
            "type": "string",
            "value": "[last('One Two Three')]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
arrayOutput String three
stringOutput String e

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/last.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/last.json

lastIndexOf(stringToSearch, stringToFind)

Returns the last position of a value within a string. The comparison is case-insensitive.

Parameters

Parameter Required Type Description
stringToSearch Yes string The value that contains the item to find.
stringToFind Yes string The value to find.

Return value

An integer that represents the last position of the item to find. The value is zero-based. If the item is not found, -1 is returned.

Examples

The following example template shows how to use the indexOf and lastIndexOf functions:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [],
    "outputs": {
        "firstT": {
            "value": "[indexOf('test', 't')]",
            "type" : "int"
        },
        "lastT": {
            "value": "[lastIndexOf('test', 't')]",
            "type" : "int"
        },
        "firstString": {
            "value": "[indexOf('abcdef', 'CD')]",
            "type" : "int"
        },
        "lastString": {
            "value": "[lastIndexOf('abcdef', 'AB')]",
            "type" : "int"
        },
        "notFound": {
            "value": "[indexOf('abcdef', 'z')]",
            "type" : "int"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
firstT Int 0
lastT Int 3
firstString Int 2
lastString Int 0
notFound Int -1

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/indexof.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/indexof.json

length(string)

Returns the number of characters in a string, or elements in an array.

Parameters

Parameter Required Type Description
arg1 Yes array or string The array to use for getting the number of elements, or the string to use for getting the number of characters.

Return value

An int.

Examples

The following example template shows how to use length with an array and string:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "arrayToTest": {
            "type": "array",
            "defaultValue": [
                "one",
                "two",
                "three"
            ]
        },
        "stringToTest": {
            "type": "string",
            "defaultValue": "One Two Three"
        }
    },
    "resources": [],
    "outputs": {
        "arrayLength": {
            "type": "int",
            "value": "[length(parameters('arrayToTest'))]"
        },
        "stringLength": {
            "type": "int",
            "value": "[length(parameters('stringToTest'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
arrayLength Int 3
stringLength Int 13

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/length.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/length.json

padLeft(valueToPad, totalLength, paddingCharacter)

Returns a right-aligned string by adding characters to the left until reaching the total specified length.

Parameters

Parameter Required Type Description
valueToPad Yes string or int The value to right-align.
totalLength Yes int The total number of characters in the returned string.
paddingCharacter No single character The character to use for left-padding until the total length is reached. The default value is a space.

If the original string is longer than the number of characters to pad, no characters are added.

Return value

A string with at least the number of specified characters.

Examples

The following example template shows how to pad the user-provided parameter value by adding the zero character until it reaches the total number of characters.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "testString": {
            "type": "string",
            "defaultValue": "123"
        }
    },
    "resources": [],
    "outputs": {
        "stringOutput": {
            "type": "string",
            "value": "[padLeft(parameters('testString'),10,'0')]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
stringOutput String 0000000123

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/padleft.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/padleft.json

replace(originalString, oldString, newString)

Returns a new string with all instances of one string replaced by another string.

Parameters

Parameter Required Type Description
originalString Yes string The value that has all instances of one string replaced by another string.
oldString Yes string The string to be removed from the original string.
newString Yes string The string to add in place of the removed string.

Return value

A string with the replaced characters.

Examples

The following example template shows how to remove all dashes from the user-provided string, and how to replace part of the string with another string.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "testString": {
            "type": "string",
            "defaultValue": "123-123-1234"
        }
    },
    "resources": [],
    "outputs": {
        "firstOutput": {
            "type": "string",
            "value": "[replace(parameters('testString'),'-', '')]"
        },
        "secodeOutput": {
            "type": "string",
            "value": "[replace(parameters('testString'),'1234', 'xxxx')]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
firstOutput String 1231231234
secodeOutput String 123-123-xxxx

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/replace.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/replace.json

skip(originalValue, numberToSkip)

Returns a string with all the characters after the specified number of characters, or an array with all the elements after the specified number of elements.

Parameters

Parameter Required Type Description
originalValue Yes array or string The array or string to use for skipping.
numberToSkip Yes int The number of elements or characters to skip. If this value is 0 or less, all the elements or characters in the value are returned. If it is larger than the length of the array or string, an empty array or string is returned.

Return value

An array or string.

Examples

The following example template skips the specified number of elements in the array, and the specified number of characters in a string.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "testArray": {
            "type": "array",
            "defaultValue": [
                "one",
                "two",
                "three"
            ]
        },
        "elementsToSkip": {
            "type": "int",
            "defaultValue": 2
        },
        "testString": {
            "type": "string",
            "defaultValue": "one two three"
        },
        "charactersToSkip": {
            "type": "int",
            "defaultValue": 4
        }
    },
    "resources": [],
    "outputs": {
        "arrayOutput": {
            "type": "array",
            "value": "[skip(parameters('testArray'),parameters('elementsToSkip'))]"
        },
        "stringOutput": {
            "type": "string",
            "value": "[skip(parameters('testString'),parameters('charactersToSkip'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
arrayOutput Array ["three"]
stringOutput String two three

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/skip.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/skip.json

split(inputString, delimiter)

Returns an array of strings that contains the substrings of the input string that are delimited by the specified delimiters.

Parameters

Parameter Required Type Description
inputString Yes string The string to split.
delimiter Yes string or array of strings The delimiter to use for splitting the string.

Return value

An array of strings.

Examples

The following example template splits the input string with a comma, and with either a comma or a semi-colon.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "firstString": {
            "type": "string",
            "defaultValue": "one,two,three"
        },
        "secondString": {
            "type": "string",
            "defaultValue": "one;two,three"
        }
    },
    "variables": {
        "delimiters": [ ",", ";" ]
    },
    "resources": [],
    "outputs": {
        "firstOutput": {
            "type": "array",
            "value": "[split(parameters('firstString'),',')]"
        },
        "secondOutput": {
            "type": "array",
            "value": "[split(parameters('secondString'),variables('delimiters'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
firstOutput Array ["one", "two", "three"]
secondOutput Array ["one", "two", "three"]

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/split.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/split.json

startsWith(stringToSearch, stringToFind)

Determines whether a string starts with a value. The comparison is case-insensitive.

Parameters

Parameter Required Type Description
stringToSearch Yes string The value that contains the item to find.
stringToFind Yes string The value to find.

Return value

True if the first character or characters of the string match the value; otherwise, False.

Examples

The following example template shows how to use the startsWith and endsWith functions:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [],
    "outputs": {
        "startsTrue": {
            "value": "[startsWith('abcdef', 'ab')]",
            "type" : "bool"
        },
        "startsCapTrue": {
            "value": "[startsWith('abcdef', 'A')]",
            "type" : "bool"
        },
        "startsFalse": {
            "value": "[startsWith('abcdef', 'e')]",
            "type" : "bool"
        },
        "endsTrue": {
            "value": "[endsWith('abcdef', 'ef')]",
            "type" : "bool"
        },
        "endsCapTrue": {
            "value": "[endsWith('abcdef', 'F')]",
            "type" : "bool"
        },
        "endsFalse": {
            "value": "[endsWith('abcdef', 'e')]",
            "type" : "bool"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
startsTrue Bool True
startsCapTrue Bool True
startsFalse Bool False
endsTrue Bool True
endsCapTrue Bool True
endsFalse Bool False

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/startsendswith.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/startsendswith.json

string(valueToConvert)

Converts the specified value to a string.

Parameters

Parameter Required Type Description
valueToConvert Yes Any The value to convert to string. Any type of value can be converted, including objects and arrays.

Return value

A string of the converted value.

Examples

The following example template shows how to convert different types of values to strings:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "testObject": {
            "type": "object",
            "defaultValue": {
                "valueA": 10,
                "valueB": "Example Text"
            }
        },
        "testArray": {
            "type": "array",
            "defaultValue": [
                "a",
                "b",
                "c"
            ]
        },
        "testInt": {
            "type": "int",
            "defaultValue": 5
        }
    },
    "resources": [],
    "outputs": {
        "objectOutput": {
            "type": "string",
            "value": "[string(parameters('testObject'))]"
        },
        "arrayOutput": {
            "type": "string",
            "value": "[string(parameters('testArray'))]"
        },
        "intOutput": {
            "type": "string",
            "value": "[string(parameters('testInt'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
objectOutput String {"valueA":10,"valueB":"Example Text"}
arrayOutput String ["a","b","c"]
intOutput String 5

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/string.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/string.json

substring(stringToParse, startIndex, length)

Returns a substring that starts at the specified character position and contains the specified number of characters.

Parameters

Parameter Required Type Description
stringToParse Yes string The original string from which the substring is extracted.
startIndex No int The zero-based starting character position for the substring.
length No int The number of characters for the substring. Must refer to a location within the string.

Return value

The substring.

Remarks

The function fails when the substring extends beyond the end of the string. The following example fails with the error "The index and length parameters must refer to a location within the string. The index parameter: '0', the length parameter: '11', the length of the string parameter: '10'.".

"parameters": {
    "inputString": { "type": "string", "value": "1234567890" }
},
"variables": { 
    "prefix": "[substring(parameters('inputString'), 0, 11)]"
}

Examples

The following example template extracts a substring from a parameter.

{
	"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
	"contentVersion": "1.0.0.0",
	"parameters": {
		"testString": {
			"type": "string",
			"defaultValue": "one two three"
		}
	},
	"resources": [],
	"outputs": {
		"substringOutput": {
			"value": "[substring(parameters('testString'), 4, 3)]",
			"type": "string"
		}
	}
}

The output from the preceding example with the default values is:

Name Type Value
substringOutput String two

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/substring.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/substring.json

take(originalValue, numberToTake)

Returns a string with the specified number of characters from the start of the string, or an array with the specified number of elements from the start of the array.

Parameters

Parameter Required Type Description
originalValue Yes array or string The array or string to take the elements from.
numberToTake Yes int The number of elements or characters to take. If this value is 0 or less, an empty array or string is returned. If it is larger than the length of the given array or string, all the elements in the array or string are returned.

Return value

An array or string.

Examples

The following example template takes the specified number of elements from the array, and characters from a string.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "testArray": {
            "type": "array",
            "defaultValue": [
                "one",
                "two",
                "three"
            ]
        },
        "elementsToTake": {
            "type": "int",
            "defaultValue": 2
        },
        "testString": {
            "type": "string",
            "defaultValue": "one two three"
        },
        "charactersToTake": {
            "type": "int",
            "defaultValue": 2
        }
    },
    "resources": [],
    "outputs": {
        "arrayOutput": {
            "type": "array",
            "value": "[take(parameters('testArray'),parameters('elementsToTake'))]"
        },
        "stringOutput": {
            "type": "string",
            "value": "[take(parameters('testString'),parameters('charactersToTake'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
arrayOutput Array ["one", "two"]
stringOutput String on

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/take.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/take.json

toLower(stringToChange)

Converts the specified string to lower case.

Parameters

Parameter Required Type Description
stringToChange Yes string The value to convert to lower case.

Return value

The string converted to lower case.

Examples

The following example template converts a parameter value to lower case and to upper case.

{
	"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
	"contentVersion": "1.0.0.0",
	"parameters": {
		"testString": {
			"type": "string",
			"defaultValue": "One Two Three"
		}
	},
	"resources": [],
	"outputs": {
		"toLowerOutput": {
			"value": "[toLower(parameters('testString'))]",
			"type": "string"
		},
        "toUpperOutput": {
            "type": "string",
            "value": "[toUpper(parameters('testString'))]"
        }
	}
}

The output from the preceding example with the default values is:

Name Type Value
toLowerOutput String one two three
toUpperOutput String ONE TWO THREE

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/tolower.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/tolower.json

toUpper(stringToChange)

Converts the specified string to upper case.

Parameters

Parameter Required Type Description
stringToChange Yes string The value to convert to upper case.

Return value

The string converted to upper case.

Examples

The following example template converts a parameter value to lower case and to upper case.

{
	"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
	"contentVersion": "1.0.0.0",
	"parameters": {
		"testString": {
			"type": "string",
			"defaultValue": "One Two Three"
		}
	},
	"resources": [],
	"outputs": {
		"toLowerOutput": {
			"value": "[toLower(parameters('testString'))]",
			"type": "string"
		},
        "toUpperOutput": {
            "type": "string",
            "value": "[toUpper(parameters('testString'))]"
        }
	}
}

The output from the preceding example with the default values is:

Name Type Value
toLowerOutput String one two three
toUpperOutput String ONE TWO THREE

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/tolower.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/tolower.json

trim (stringToTrim)

Removes all leading and trailing white-space characters from the specified string.

Parameters

Parameter Required Type Description
stringToTrim Yes string The value to trim.

Return value

The string without leading and trailing white-space characters.

Examples

The following example template trims the white-space characters from the parameter.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "testString": {
            "type": "string",
            "defaultValue": "    one two three   "
        }
    },
    "resources": [],
    "outputs": {
        "return": {
            "type": "string",
            "value": "[trim(parameters('testString'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
return String one two three

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/trim.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/trim.json

uniqueString (baseString, ...)

Creates a deterministic hash string based on the values provided as parameters.

Parameters

Parameter Required Type Description
baseString Yes string The value used in the hash function to create a unique string.
additional parameters as needed No string You can add as many strings as needed to create the value that specifies the level of uniqueness.

Remarks

This function is helpful when you need to create a unique name for a resource. You provide parameter values that limit the scope of uniqueness for the result. You can specify whether the name is unique down to subscription, resource group, or deployment.

The returned value is not a random string, but rather the result of a hash function. The returned value is 13 characters long. It is not globally unique. You may want to combine the value with a prefix from your naming convention to create a name that is meaningful. The following example shows the format of the returned value. The actual value varies by the provided parameters.

tcvhiyu5h2o5o

The following examples show how to use uniqueString to create a unique value for commonly used levels.

Unique scoped to subscription

"[uniqueString(subscription().subscriptionId)]"

Unique scoped to resource group

"[uniqueString(resourceGroup().id)]"

Unique scoped to deployment for a resource group

"[uniqueString(resourceGroup().id, deployment().name)]"

The following example shows how to create a unique name for a storage account based on your resource group. Inside the resource group, the name is not unique if constructed the same way.

"resources": [{ 
    "name": "[concat('storage', uniqueString(resourceGroup().id))]", 
    "type": "Microsoft.Storage/storageAccounts", 
    ...

Return value

A string containing 13 characters.

Examples

The following example template returns results from uniquestring:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [],
    "outputs": {
        "uniqueRG": {
            "value": "[uniqueString(resourceGroup().id)]",
            "type" : "string"
        },
        "uniqueDeploy": {
            "value": "[uniqueString(resourceGroup().id, deployment().name)]",
            "type" : "string"
        }
    }
}

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/uniquestring.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/uniquestring.json

uri (baseUri, relativeUri)

Creates an absolute URI by combining the baseUri and the relativeUri string.

Parameters

Parameter Required Type Description
baseUri Yes string The base uri string.
relativeUri Yes string The relative uri string to add to the base uri string.

The value for the baseUri parameter can include a specific file, but only the base path is used when constructing the URI. For example, passing http://contoso.com/resources/azuredeploy.json as the baseUri parameter results in a base URI of http://contoso.com/resources/.

Return value

A string representing the absolute URI for the base and relative values.

Examples

The following example shows how to construct a link to a nested template based on the value of the parent template.

"templateLink": "[uri(deployment().properties.templateLink.uri, 'nested/azuredeploy.json')]"

The following example template shows how to use uri, uriComponent, and uriComponentToString:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "variables": {
        "uriFormat": "[uri('http://contoso.com/resources/', 'nested/azuredeploy.json')]",
        "uriEncoded": "[uriComponent(variables('uriFormat'))]" 
    },
    "resources": [
    ],
    "outputs": {
        "uriOutput": {
            "type": "string",
            "value": "[variables('uriFormat')]"
        },
        "componentOutput": {
            "type": "string",
            "value": "[variables('uriEncoded')]"
        },
        "toStringOutput": {
            "type": "string",
            "value": "[uriComponentToString(variables('uriEncoded'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
uriOutput String http://contoso.com/resources/nested/azuredeploy.json
componentOutput String http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json
toStringOutput String http://contoso.com/resources/nested/azuredeploy.json

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/uri.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/uri.json

uricomponent(stringToEncode)

Encodes a URI.

Parameters

Parameter Required Type Description
stringToEncode Yes string The value to encode.

Return value

A string of the URI encoded value.

Examples

The following example template shows how to use uri, uriComponent, and uriComponentToString:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "variables": {
        "uriFormat": "[uri('http://contoso.com/resources/', 'nested/azuredeploy.json')]",
        "uriEncoded": "[uriComponent(variables('uriFormat'))]" 
    },
    "resources": [
    ],
    "outputs": {
        "uriOutput": {
            "type": "string",
            "value": "[variables('uriFormat')]"
        },
        "componentOutput": {
            "type": "string",
            "value": "[variables('uriEncoded')]"
        },
        "toStringOutput": {
            "type": "string",
            "value": "[uriComponentToString(variables('uriEncoded'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
uriOutput String http://contoso.com/resources/nested/azuredeploy.json
componentOutput String http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json
toStringOutput String http://contoso.com/resources/nested/azuredeploy.json

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/uri.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/uri.json

uriComponentToString(uriEncodedString)

Returns a string of a URI encoded value.

Parameters

Parameter Required Type Description
uriEncodedString Yes string The URI encoded value to convert to a string.

Return value

A decoded string of URI encoded value.

Examples

The following example template shows how to use uri, uriComponent, and uriComponentToString:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "variables": {
        "uriFormat": "[uri('http://contoso.com/resources/', 'nested/azuredeploy.json')]",
        "uriEncoded": "[uriComponent(variables('uriFormat'))]" 
    },
    "resources": [
    ],
    "outputs": {
        "uriOutput": {
            "type": "string",
            "value": "[variables('uriFormat')]"
        },
        "componentOutput": {
            "type": "string",
            "value": "[variables('uriEncoded')]"
        },
        "toStringOutput": {
            "type": "string",
            "value": "[uriComponentToString(variables('uriEncoded'))]"
        }
    }
}

The output from the preceding example with the default values is:

Name Type Value
uriOutput String http://contoso.com/resources/nested/azuredeploy.json
componentOutput String http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json
toStringOutput String http://contoso.com/resources/nested/azuredeploy.json

To deploy this example template with Azure CLI, use:

az group deployment create -g functionexamplegroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/uri.json

To deploy this example template with PowerShell, use:

New-AzureRmResourceGroupDeployment -ResourceGroupName functionexamplegroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/functions/uri.json

Next steps