The string template variable supports the use of valid expressions, which can embed variables, random data, and the result of mathematical operations. This guide provides an overview of the different types of valid expressions that are supported by the string template variable:
Valid expression syntax
Valid expressions are delimited by double curly braces: {{ }}. Variables are also prepended by an @ symbol. Here are some examples of valid expressions:
-
{{@username}}: references the value of a variableusername -
{{alpha:6}}: generates a random string of six upper and lower case letters -
{{fake.name.firstName}}: generates a random first name -
{{(6 + 10) / 2}}: divides the sum of six and ten by two -
{{date}}: generates a timestamp. If you need a formatted date, see our guide on working with dates in mabl.
Referencing variables
Using mabl variable syntax, you can embed a variable within a string template variable.
mabl variable syntax
The syntax for referencing variables in mabl is {{@variable_name}}. For example, if you want to reference a variable called "user_id", you can write {{@user_id}}
In the Property text field, type the {{@variable_name}} in the spot where you want to add the original variable. The Current value box will show a preview of your new variable.

Give the new variable a name and click OK .
Limitations to referencing variables
Variable interpolation is not supported in data-driven variables or environment variables. This means that their values cannot contain references to another variable, such as {{@anotherVar}}.
Macros
Macros are useful for generating random strings. They include a character type followed by a colon and a number, where the number indicates the number of random characters to be created. Here is the table of supported macros that can be used for string templates:
| Macro | Description | Example |
|---|---|---|
alpha |
Upper and lower case letters | {{alpha:3}} |
alphaLower |
Lowercase letters (a-z) | abc{{alphaLower:4}} |
alphaUpper |
Uppercase letters (A-Z) | ABC{{alphaUpper:5}} |
digit |
Numbers (0-9) | 123-{{digit:4}} |
alnum |
Alphanumeric (letters and numbers) | random{{alnum:6}} |

Faker expressions
mabl can also generate realistic random data using faker expressions in the following form: {{fake.type.subtype}}. For a complete reference, check out the documentation from https://v6.fakerjs.dev. Please note that only the English locale is supported.
The following table provides some common faker expressions that you can use to create variables with random data:
| Expression | Expectation | Sample result |
|---|---|---|
{{fake.name.firstName}} |
Random first name | "Garfield" |
{{fake.name.lastName}} |
Random last name | "Larson" |
{{fake.address.streetAddress}} |
Random street address | "840 Roberts Burg" |
{{fake.address.city}} |
Random city name | "Manteton" |
{{fake.address.state}} |
Random US state name | "North Carolina" |
{{fake.address.zipCode}} |
Random US zip code | "02160" |
{{fake.address.countryCode}} |
Random 2-letter country code | "TN" |
{{fake.company.companyName}} |
Random company name | "Sawayn Group" |
{{fake.internet.email}} |
Random email address | "Rafaela19@gmail.com" |
{{fake.phone.phoneNumber}} |
Random phone number in one of multiple formats | "1-968-628-9831 x738" |
{{fake.phone.phoneNumberFormat}} |
Random phone number in the format ###-###-#### | "776-705-5652" |
{{fake.lorem.text}} |
Random filler text | "consequatur omnis neque" |
{{fake.random.uuid}} |
Random UUID | "71bcc5d3-7f24-4b08-bcf8-f9b8e0d6d913" |
{{fake.finance.amount}} |
Random financial amount | "17.78" |
Random values in API tests
Faker expressions are not supported in API tests. To generate random data in an API test, use Postman dynamic variables. Learn more about API test variables here.
Mathematical operations
mabl can perform basic math operations within the string template and save the results to a new variable or overwrite an existing variable. Formulating the expression is important for the correct results. The mathematical expressions must be enclosed by the double curly braces to be evaluated.
Here are examples of how to create valid math expressions in the string template:
- Math expressions are evaluated under the PEMDAS rules.
{{5 + 3 / 2}}will evaluate to 6.5- Use parentheses to evaluate math operations in the specified order.
{{(5 + 3) / 2}}will evaluate to 4- Math operations may be combined with other values, such as a currency or percentage symbol.
${{(5 + 3 ) / 2}}will evaluate to $4- Math operations may include macros and variables, as long as the value is a number
{{digit:1+100}}or{{@sample_var/2}}
Advanced math expressions
mabl also supports certain advanced math functions, including rounding, absolute values, and random integers.
Rounding
The function round(number, numberOfDecimalPlaces) rounds the result of a math calculation to numberOfDecimalPlaces. For example, {{round(1/3,2)}} outputs the value 0.33.
JavaScript Floating Point Precision
Due to rounding errors stemming from how floating point numbers are stored, arithmetic expressions like 0.1 + 0.2 === 0.3 will return false. To resolve this, the result needs to be rounded, e.g. round(0.1 + 0.2, 1) or (0.1 + 0.2).toFixed(1).
Absolute values
The function abs(number) returns the absolute value of a math calculation. For example, {{abs(-6)}} will evaluate to 6.
Random values
The function randomInt(min, max) returns a random integer greater than or equal to min but LESS than max. For example, {{randomInt(0,11)}} will return a random integer between 0 and 10.
Expressions that output random integers may also include variables. For example, to generate a random value between 1 and the variable value {{@total_count}}, you could use this expression: {{randomInt(0, @total_count)+1}}.