Escape Double Curly Braces - Mustache?

Is there a way to override Postman’s default variable substitution if the field has double curly braces in it, such as when submitting a mustache template which also uses double curly braces.

For example, submitting this as a body to an endpoint:

"alertConfig": "{\"priority\": \"P2\",\"message\": \"{{alertName}}\"}",
"some other field": "some value"

Where the {{alertName}} needs to be exactly that. It should not be substituted for whatever is set as that variable in whatever scope.

I know we can just not set the variable, but wondering if there’s a way to tell postman “don’t substitute anything in double curly braces in this block”. Or on individual instances?


Hey @fedorovs :wave: Welcome to the Postman Community :rocket:

If you have not set a corresponding variable (in all of global, collection, environment variables) - in this case “alertName” - the string enclosed by curly braces will not be replaced with any variable value.
To test, I have pasted the above body without setting any variable - the following shows the actual request body being sent. As you can see, {{aleartName}} is sent as is.

Hope this clarifies, but please feel free to reach out if you have further questions :slightly_smiling_face:

Hi Tae,
Thanks for the reply. I did mention I knew this was an option, however it’s not something we can count on. In this case, the variable alertName is also set as an environment variable because there is an “alertName” in the request body.

I realize I can just rename the variable to something else to solve the issue for this one specific use case, but I am trying to create a versatile collection I can share, and unless there’s some way to prevent certain variable names, I can’t guarantee users won’t also select the same variable name later on and not realize the implications of doing do.

So the question is, is there a way to prevent Postman from substituting variables when there are double curly braces.

Hey @fedorovs!

Sorry for overlooking the place you mentioned about not including in the variable. As far as I am aware, there is no way to disable substituting for a variable. But including a script like below might help here to check if the variable name exists and updates if it does exist:

if (pm.variables.get('alertName')) {
    pm.variables.set('alertName', '{{alertName}}')