Inline Expressions
Inline Expressions let you dynamically generate and manipulate values using the {{...}}
syntax.
Use them in variables, headers, bodies, scripts, and other places where values are expected.
Grammar
expression := literal | variable | functionCall | operation | array
literal := "double-quoted string" | 'single-quoted string' | number | boolean | null
variable := identifier | variable.property | variable[index]
functionCall := functionName [ "(" [expression[, expression]*] ")" ]
operation := expression operator expression
array := "[" [expression[, expression]*] "]"
operator := "+" | "-" | "*" | "/" | "??"
Expression Types
Literals
- Strings: Single or double-quoted
{{"Hello"}}
,{{'World'}}
- Numbers: Integers or decimals
{{123}}
,{{45.67}}
- Booleans:
{{true}}
,{{false}}
- Null:
{{null}}
Variables
Access variables using dot notation or brackets:
Examples: {{myVar}}
, {{user.name}}
, {{users[0].role}}
Arrays
Define arrays with square brackets. Elements can include literals, variables, functions, and nested expressions:
Examples:
{{[1, 2, 3]}}
{{["admin", "user", $randomEmail()]}}
{{[myVar, $randomInt(1, 10) * 5]}}
Function Calls
- Without arguments:
{{$randomEmail}}
or{{$randomEmail()}}
- With arguments:
{{$pickOne(["admin", "user"])}}
- Nested calls:
{{$randomInt($randomInt(1, 5), 100)}}
Operations
- Arithmetic:
{{5 + myIntVar * $randomInt(1, 10)}}
- String concatenation:
{{"User: " + $randomUserName}}
- Coalesce (
??
): Returns right value if left isnull
or errors
Example:{{token ?? $eval("getToken()")}}
Using Inline Expressions in Scripts
Inline expressions can be evaluated directly from scripts using the same syntax as variables. Use jc.variables.get
to
resolve an inline expression dynamically:
// Evaluate an arithmetic expression with random values
const result = jc.variables.get("123 + myVar + $randomInt(1, 10)");
console.log(result);
// Prompt the user for input and use it in the script
const userNumber = jc.variables.get("$intInput('Enter a number')");
console.log(`User entered: ${userNumber}`);
Built-In Functions
JetClient provides a comprehensive set of built-in functions for generating random values, collecting user input, reading files, executing JavaScript, and running shell commands. For the complete list, see Functions.