Skip to main content
Expressions are the mechanism Devset uses to make workflow payloads dynamic. Instead of hardcoding field values, you write expression objects that the engine resolves at runtime — generating random data, reading from the current event payload, pulling values out of workflow state, or computing results with built-in functions. Expressions are valid anywhere a value appears inside set, state, emit, repeatWhile, repeatUntil, and key.

Value Types

Devset recognises four distinct value types. You can mix them freely within any stage.

Plain Literal

A bare JSON value — string, number, boolean, or null. The engine uses it exactly as written.

Function Call ($fn)

An object with a "$fn" key whose value is a function expression string. The engine calls the named built-in function and substitutes the return value.

Relative Field Reference ($ref)

An object with a "$ref" key that names a field in the current stage’s payload. Use this to read a value that was set earlier in the same stage’s set block, or carried over via source: "previous-stage".
$ref reads from the payload object being assembled by the current stage. To read from workflow-scoped state, use $path instead.

Absolute Path Reference ($path)

An object with a "$path" key containing a dot-notation path into the workflow state. Use this to read any value that was written by a previous stage’s state block.

Conditional Values (when)

The when form lets you express if/else logic inline. The engine evaluates the when expression; if it is truthy, the value is used, otherwise default is used.
You can nest any expression type inside value and default:

Path References in Functions

Functions that take field arguments accept two path syntaxes: Examples:
Reads the unitPrice field from the current payload and checks whether it is greater than zero.
Reads count from state.batch and checks whether it is less than 50.
Adds 1 to the index value stored in state.sequence.

Built-in Function Reference

Weighted choice example

This produces "completed" 70% of the time, "failed" 20% of the time, and "pending" 10% of the time.

Expressions in Context

The following workflow fragment shows all four value types and a conditional used together in a realistic stage:
  • paymentId and initiatedAt use $fn to generate random values at runtime.
  • amount, currency, and method use $fn with weighted or range functions.
  • sequenceNumber uses $path to read from workflow state.
  • reference uses $ref to copy paymentId into a second field within the same payload.
  • requiresReview uses a when conditional that checks the freshly assigned amount.
  • emit uses $fn to skip dispatch if amount is zero.
You can chain state mutations and field references across multiple stages. Write a value into state in one stage with state, then read it in a later stage with { "$path": "state.my.path" }.