Escape Single Quotes within Azure Resource Template

1 minute read

In some situations you will get into problems when creating a Azure Resource Template. I was creating a solution for a customer and had to add a Logic App to our template. That isn’t that hard I thought but when adding a Logic App to your template and making it parameterized and depending on other resources you can come into scenario’s were you will have to escape single quotes.

Looking into the documentation about azure resource templates you will not find any solution (I haven’t) so I tried a couple of escape characters and they didn’t work.

The last resort was a solution that isn’t that pretty but it works, I hope that in new releases this will be fixed.

Create a Variable

The first step for the solution is to create a variable in the template that contains a single quote.

"variables": {
  "singlequote": "'"

Use the variable

After you created the variable you can use this to combine you string values.

 "uri": "[concat('https://', reference(concat('Microsoft.Web/sites/', parameters('api_Name'))).defaultHostName, '/api/Item/', '@{encodeURIComponent(body(',variables('singlequote'), 'HTTP_GetItem',variables('singlequote'), ')?[', variables('singlequote'),'itemid_value', variables('singlequote'), '])}')]"

As you can see in the above code snip it we set the “uri” property of a Logic App component. In this specific snipt it we dynamically get the hostname of a Azure Web Site the Logic App depends on. Further up in the “uri” we need single quotes as you can see by adding the variable ‘singlequote’.