In addition to Handlebars' built-in helpers (if
, each
, etc., for more information, please have a look at Handlebars' documentation), Mockoon offers the following helpers:
Repeat the block content a random number of times if two arguments are provided, or a fixed amount of time if only one argument is provided. Set the comma
parameter to false
(default to true
) to prevent the insertion of new lines and commas by the helper.
Parameters/arguments | Type | Description |
---|---|---|
[0] | number | Minimum items |
1 | number | Maximum items |
[comma=true] | boolean | Add trailing comma |
Examples
Copytest <!-- result: test, test, test, test, test -->
Select some content depending on a variable. Behaves like a regular switch.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Value against which the switch matches the cases |
Examples
Copy"John" "Jack" "Peter"
Get the stringified value at a given path
from a data bucket selected by ID or name. This helper is designed to retrieve data to be served in a response. To reuse the retrieved data with other helpers (each
, if
, etc.), use the dataRaw
helper below.
path
supports two syntaxes, object-path or JSONPath Plus. When using object-path, properties containing dots are supported by escaping the dots: key.key\.with\.dot
.path
is omitted ({{data 'ID'}}
).🛠️ Use our online JSONPath and object-path evaluator to test your JSONPath or object-path syntaxes and view the results in real-time.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | ID or name of the data bucket |
1 | string | Path to the data bucket property |
Examples
Copy<!-- Using object-path syntax --> <!-- using JSONPath syntax -->
Get the raw value (array, object, etc.) at a given path
from a data bucket selected by ID or name. This "raw" helper is designed to work with other helpers (each
, if
, etc.). To directly use the retrieved data in the response, use data buckets direct linking or the data
helper above.
path
supports two syntaxes, object-path or JSONPath Plus. When using object-path, properties containing dots are supported by escaping the dots: key.key\.with\.dot
.path
is omitted ({{dataRaw 'ID'}}
).🛠️ Use our online JSONPath and object-path evaluator to test your JSONPath or object-path syntaxes and view the results in real-time.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | ID or name of the data bucket |
1 | string | Path to the data bucket property |
Examples
Copy<!-- Using object-path syntax --> <!-- using JSONPath syntax --> value value
Set or modify the value at a given path in a data bucket selected by ID or name. This helper can perform various operations such as setting, pushing, deleting, incrementing, decrementing, and inverting values.
path
supports the object-path syntax. When using object-path, properties containing dots are supported by escaping the dots: key.key\.with\.dot
.path
is omitted ({{setData 'operation' 'ID' '' 'value'}}
).set
, push
, del
, inc
, dec
, and invert
:
set
: Set a new value at the root level (path omitted) or at the specified path. Requires a new value.merge
: If the value at the specified path is an object, merge the new value with the existing one. Requires a new value of type object.push
: Push a new value to an array at the root level (path omitted) or at the specified path. Requires a new value and the target to be an array.del
: Delete a value at the root level (path omitted) or at the specified path. No new value required.inc
: Increment a number at the root level (path omitted) or at the specified path. Requires a number to increment by. If the value is omitted, the increment will be by 1.dec
: Decrement a number at the root level (path omitted) or at the specified path. Requires a number to decrement by. If the value is omitted, the decrement will be by 1.invert
: Invert a boolean at the root level (path omitted) or at the specified path. No new value required.Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Operation to perform (set , merge , push , del , inc , dec , invert ) |
1 | string | ID or name of the data bucket |
2 | string | Path to the data bucket property (optional) |
3 | any | New value (optional for invert , inc , dec and del ) |
Examples
Copy<!-- Add a property to the target object --> <!-- Merge the target object with the request's body -->
Create an array from the given items. This helper is mostly used with the following helpers: oneOf
, someOf
.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any | Value used to populate the array |
Examples
Copy
Select a random item in the array passed in parameters. oneOf
will return the actual value in the array. Set the stringify
parameter to true
(default to false
) to get a JSON stringified result.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any[] | Array of values |
[1 = false] | boolean | Stringify the result |
Examples
Copyresult: item2
Return an array containing a random number of items from the array passed in parameters, eventually stringified. Use it with triple curly braces to get a non-escaped JSON representation.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any[] | Array of values |
1 | number | Minimum number of items |
2 | number | Maximum number of items |
[3 = false] | boolean | Stringify the result |
Examples
Copyresult: item1,item2 <!-- Use triple curly braces to avoid Handlebars' character escaping --> result: ["item1","item2"]
Return a new string by concatenating all the elements in an array.
Arguments (ordered) | Type | Description |
---|---|---|
0 | [] | Array of values |
1 | string | Separator |
Examples
Copyresult: item1#item2#item3
Return a copy of a portion of an array from start to end indexes (not included).
Arguments (ordered) | Type | Description |
---|---|---|
0 | [] | Array of values |
1 | number | Start index |
2 | number | End index |
Examples
Copyresult: ['item1', 'item2']
Return an array or string length.
Arguments (ordered) | Type | Description |
---|---|---|
0 | [] | string | Array or string |
Examples
Copyresult: 3 result: 5
Return a filtered array. This helper can be used with data buckets, use the dataRaw for that.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any[] | Input array |
1..n | primitive or object or array | OR conditions level |
filter (array 1 2 3) 1 3 5 6 ....
.
AND
.filter (array 1 2 3) 1 3
equals fo [1,2,3].filter(x => x === 3 || x === 1)
.AND
sub-conditions list.OR
sub-conditions list.OR
(the first level of the arguments) -> AND
-> OR
-> AND
-> ...AND
queries with objects please check the object helper documentation.Structure
Copy<!-- Filter on object keys --> <!-- Filter on nested object keys --> <!-- filter query base OR structure --> result: c1 OR c2 OR c3 <!-- filter query base AND structure (the AND conditions described as sub-conditions) --> result: items that fit to c1 AND c2 AND c3 <!-- filter query a few OR from several AND conditions --> result: (a1 AND a2 AND a3) OR (b1 AND b2 AND b3) OR (c1 AND c2 AND c3) <!-- filter with complex nested structure --> results: items that fit to (a1 AND a2 AND (x1 OR x2) ) OR (b1 AND b2 AND b3)
Examples
Copy<!-- Simple OR filter --> result: 1,3 <!-- Simple OR filter --> result: item1,item2,item3,item3 <!-- Data bucket get all users with type='item1' --> <!-- Data bucket get all users with type='item1' OR type='item2' OR type='item3' --> <!-- Data bucket get all users with type='item1' AND category='some-category' --> <!-- Data bucket get all users with type='item1' OR category='some-category' --> <!-- Mixed data filter -->
Return an object that can be used in other helpers.
Parameters (named) | Type | Description |
---|---|---|
[string]=any | any | key=value notation of the object properties |
Examples
Copyresult: {type: 'item1'} result: {type: 'item1', category: 'cat1'} result: {type: [1,2,3]} result: {type: [1,2,3]} result: {type: [1,3]}
Merge two objects. The second object's properties will overwrite the first object's properties if they have the same key.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | object[] | Objects to merge |
Examples
Copy<!-- result: {key1: 'value1', key2: 'value2'} --> <!-- Adding an id to the request's body -->
Return a sorted array of strings or numbers. To sort array of objects, use the sortBy helper.
Arguments (ordered) | Type | Description |
---|---|---|
0 | [] | Input array |
[1 = asc] | string | Sort order ('asc' or 'desc') |
Examples
Copyresult: ['item3','item2','item1'] result: ['item1','item2','item3']
Return an array of objects sorted by a given key. This helper can be used with data buckets, use the dataRaw for that.
Arguments (ordered) | Type | Description |
---|---|---|
0 | object[] | Input array of objects |
1 | string | Object key to sort the array by |
[2 = asc] | string | Sort order ('asc' or 'desc') |
Examples
Copyresult: [{"key2": 20, "key1": 10}, {"key2": 25, "key1": 15}, {"key2": 30, "key1": 30}]
Return an array with the elements in reverse order.
Arguments (ordered) | Type | Description |
---|---|---|
0 | [] | Input array |
Examples
Copyresult: ['item3','item2','item1']
Add the numbers passed as parameters to each others. Unrecognized strings passed as arguments will be ignored.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any[] | Value of the operandes (can process numbers and strings) |
Examples
Copyresult: '2' result: '2' result: '2'
Subtract the numbers passed as parameters to the first parameter. Unrecognized strings passed as arguments will be ignored.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any[] | Value of the operandes (can process numbers and strings) |
Examples
Copyresult: '1' result: '1' result: '1'
Multiply the numbers passed as parameters to each others. Unrecognized strings passed as arguments will be ignored.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any[] | Value of the operandes (can process numbers and strings) |
Examples
Copyresult: '6' result: '6' result: '6'
Divide the first parameter by the other numbers passed as parameters. Unrecognized strings passed as arguments will be ignored.
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any[] | Value of the operandes (can process numbers and strings) |
Examples
Copyresult: '2' result: '2' result: '2'
Compute the modulo of the first parameter by the second.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First value (can process numbers and strings) |
1 | number | Second value (can process numbers and strings) |
Examples
Copyresult: '1' result: '1' result: '1'
Ceil the value of the number passed as parameter.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Value to ceil (can process numbers and strings) |
Examples
Copyresult: '2' result: '2'
Floor the value of the number passed as parameter.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Value to floor (can process numbers and strings) |
Examples
Copyresult: '2' result: '2'
Verify if two numbers or strings are equal. Returns a boolean.
Returns false if type of the value not equals.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | number | First number or string |
1 | string | number | Second number or string |
Examples
Copytrue Result: true true false Result: false true Result: true
Verify if the first number is greater than the second number. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
Verify if the first number is greater than or equal to the second number. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
Verify if the first number is lower than the second number. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
Verify if the first number is lower than or equal to the second number. Returns a boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | First number |
1 | number | Second number |
Examples
Copytrue Result: true
Format a number using fixed-point notation.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | A number |
1 | number | Number of digits |
Examples
CopyResult: 1.11
Return the value of a number rounded to the nearest integer.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | A number to round |
Examples
CopyResult: 0
Add a newline \n
.
Examples
Copy
Encode the parameter as base64. This can be used as an inline helper or block helper (see examples below).
Arguments (ordered) | Type | Description |
---|---|---|
[0] | any | Value to encode (optional when used as a block helper) |
Examples
Copyfirstname,lastname,countryCode ,,
🛠️ Use our online base64 encoder/decoder to get a preview of the encoded content and validate a base64 string.
Decode a base64 string. This can be used as an inline helper or block helper (see examples below).
Arguments (ordered) | Type | Description |
---|---|---|
[0] | string | Base64 string to decode (optional when used as a block helper) |
Examples
Copy
🛠️ Use our online base64 encoder/decoder to get a preview of the encoded content and validate a base64 string.
Create a valid ObjectId. It can generates the ObjectId based on the specified time (in seconds) or from a 12 byte string that will act as a seed. Syntax is based on bson-objectid package.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | number | Seed |
Examples
Copy
Search whether a string can be found in another string and returns the appropriate boolean.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Data to search into |
1 | any | Data to search |
Examples
Copyresult: true
Return a portion of a string starting at the specified index and extending for a given number of characters afterwards.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Starting index |
[1 = max length] | any | Length |
Examples
Copyresult: 'data'
Return the first string parameter lowercased.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | String to lowercase |
Examples
Copyresult: 'abcd'
Return the first string parameter uppercased.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | String to uppercase |
Examples
Copyresult: 'ABCD'
Split a string and return an array containing the multiples substrings. This helper can be used within handlebars' iterative helpers such as each
. (Default separator is " ")
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Data to split |
1 | string | Separator |
Examples
Copyitem, result: item1,item2,item3,item4 , result: This,is,my,string,
Return objects and arrays as a formatted JSON string indented with two spaces. This helper requires to be used with triple curly braces ({{{stringify ...}}}
) to avoid escaping of the JSON string by Handlebars.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Object or array |
Examples
Considering an entering body:
Copy{ "prop1": "123", "prop2": { "data": "test" } }
Copy
Copy{ "data": "test" }
Parse a valid JSON string. The result can be used with other helpers like each
, if
, oneOf
, lookup
, etc.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Valid JSON string to parse |
Examples
Copyvalue value result: 5 or 56 or 98 result: test <!-- Calling with a query string: ?json={"data":"test"} --> result: test
Concatenate multiple primitive values into a single string, or multiple arrays into a single array. This helper can concatenate results from other helpers, or be used as a parameter of another helper (see examples below).
Arguments (ordered) | Type | Description |
---|---|---|
0..n | any | Values or arrays to concatenate |
Examples
Copy... ...
Return the index of the searched 'data' inside the string. A last parameter (number) can be passed to start the search at a specific index.
Arguments (ordered) | Type | Description |
---|---|---|
0 | any | Data to search into |
1 | any | Data to search |
[2 = 0] | number | Search starting index |
Examples
Copyresult: 5
Parse a number from a string.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | String to parse |
Pads a string with a given string (repeated, if needed) until the resulting string reaches the given length. The padding is applied from the start of the string.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | String to pad |
1 | number | pad length |
[2 = ' '] | string | Padding character(s) (default to blank space) |
Copyresult: 00005
Pads a string with a given string (repeated, if needed) until the resulting string reaches the given length. The padding is applied from the end of the string.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | String to pad |
1 | number | pad length |
[2 = ' '] | string | Padding character(s) (default to blank space) |
Examples
Copyresult: 50000
Display the current time in the chosen format. Format syntax is based on date-fns v3 format
function and is optional (default to ISO string).
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Date format |
Examples
Copy
Shift a date by adding the number of years
, months
, etc. passed as parameters. The date
and format
parameters are optional. The helper will return the current date and time as an ISO string if omitted (yyyy-MM-ddTHH:mm:ss.SSSxxx
). The formatting uses date-fns v3 format
function.
Parameters (named) | Type | Description |
---|---|---|
date | string | Date to shift |
[format = 'yyyy-MM-ddTHH:mm:ss.SSSxxx'] | string | Format of the shifted date |
[years = 0] | number | Years to shift |
[months = 0] | number | Months to shift |
[days = 0] | number | Days to shift |
[hours = 0] | number | Hours to shift |
[minutes = 0] | number | Minutes to shift |
[seconds = 0] | number | Seconds to shift |
Examples
Copy
Return a random formatted date (using date-fns v3 format
function) between a minimum and a maximum. Uses faker 'date.between'
to generate the random date.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Starting date |
1 | string | Ending date |
2 | string | Date format |
Examples
Copy
Return a random formatted time (using date-fns v3 format
function) between a minimum and a maximum. Uses faker 'date.between'
to generate the random time.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Starting time |
1 | number | Ending time |
2 | string | Time format |
Examples
Copy
Return a formatted date (using date-fns v3 format
function).
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Date | Date to format |
1 | string | Output format |
Examples
Copy
Validate a date using a combination of date-fns v3 toDate
and isValid
functions. Supports various syntaxes for the date parameter (string, number, Date object): "2024-01-01", "2021-01-01T00:00:00.000Z", 1727272454000, etc.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | number | Date | Date to validate |
Examples
Copy<!-- Valid --> <!-- Valid --> <!-- Invalid --> <!-- Valid (unix time ms) --> <!-- Validate a date coming from another helper -->
Return a random integer. Alias of faker 'number.int
.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Minimum |
1 | number | Maximum |
Examples
Copy
Return a random float. Alias of faker 'number.float
with precision = 10.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Minimum |
1 | number | Maximum |
Examples
Copy
Return a random boolean. Alias of faker 'datatype.boolean'
.
Examples
Copy
Return a random title. Alias of faker 'name.prefix'
.
Arguments (ordered) | Type | Description |
---|---|---|
0 | string | Sex |
Examples:
Copy
Return a random first name. Alias of faker 'person.firstName'
.
Examples:
Copy
Return a random last name. Alias of faker 'person.lastName'
.
Examples:
Copy
Return a random company name. Alias of faker 'company.companyName'
.
Examples:
Copy
Return a random domain name. Alias of faker 'internet.domainName'
.
Examples:
Copy
Return a random top level domain. Alias of faker 'internet.domainSuffix'
.
Examples:
Copy
Return a random email address. Alias of faker 'internet.email'
.
Examples:
Copy
Return a random address. Alias of faker 'location.streetAddress'
.
Examples:
Copy
Return a random city name. Alias of faker 'location.city'
.
Examples:
Copy
Return a random country name. Alias of faker 'location.country'
.
Examples:
Copy
Return a random country code. Alias of faker 'location.countryCode'
.
Examples:
Copy
Return a random zip code. Alias of faker 'location.zipCode'
.
Examples:
Copy
Return a random zip code. Alias of faker 'location.zipCode'
.
Examples:
Copy
Return a random latitude. Alias of faker 'location.latitude'
.
Examples:
Copy
Return a random longitude. Alias of faker 'location.longitude'
.
Examples:
Copy
Return a random phone number. Alias of faker 'phone.number'
.
Examples:
Copy
Return a random color. Alias of faker 'color.human'
.
Examples:
Copy
Return a random hexadecimal color code.
Examples:
Copy
Return a random UUID. Alias of faker 'string.uuid'
.
Examples:
Copy
Return a random IP v4. Alias of faker 'internet.ipv4'
.
Examples:
Copy
Return a random IP v6. Alias of faker 'internet.ipv6'
.
Examples:
Copy
Return random lorem ipsum text. Alias of faker 'lorem.sentence'
.
Arguments (ordered) | Type | Description |
---|---|---|
0 | number | Number of words |
Examples:
Copy