synthtraffic Get started
Docs menu

Expressions

Modifiers

Modifiers change how a supported function returns its value. They are named arguments, and the compiler rejects a modifier on a function that does not support it.

The result

nullable=1 always produces null, optional=1 removes the field, and cardinality=1 reuses one value:

{"amount":20.00,"middleName":null,"segment":"retail"}
{"amount":20.00,"middleName":null,"segment":"retail"}

Modify generated order fields

YAML expression-modifiers.yaml
defaults:
  seed: 42
generators:
  - name: orders
    config:
      maxEvents: 2
    value:
      amount: =uniform(19.995, 19.995, round=2)
      middleName: =faker(person.middleName, nullable=1)
      couponCode: =string(8, optional=1)
      segment: =oneOf(retail, cardinality=1)

Null and omitted fields

  • nullable=P returns null with probability P, from 0 to 1: =faker(person.middleName, nullable=0.7).
  • optional=P omits the containing object field with probability P: couponCode: =string(8, optional=0.8).

optional removes the field entirely; it does not return null. Both probabilities must be literal numbers from 0 to 1.

Value pools and uniqueness

  • cardinality=N builds a deterministic pool of N distinct values, then reuses values from that pool: =faker(company.name, cardinality=20).
  • unique=true rejects values already returned by the same expression stream: =oneOf(pending, shipped, unique=true).

cardinality must be a positive integer, and unique must be written exactly as unique=true. Synthtraffic tries up to 10,000 draws to satisfy a new pool or unique value, then stops with an exhaustion error. A requested cardinality larger than the function’s possible output—such as three unique values from bool()—cannot succeed. Use unique=true on small sets such as oneOf or bool. uuid() already draws from a large space, so you do not need it there.

Numeric output

  • round=N rounds to N decimal places and preserves that scale in JSON. N must be a non-negative integer.
  • min=X and max=X clamp normal output after generation and before rounding.
price: =uniform(10, 100, round=2)
score: =normal(mean=50, sd=10, min=0, max=100, round=1)
total: =multiply($unitPrice, $quantity, round=2)

With seed 42 and unitPrice: 19.99, quantity: 3:

{"price":41.91,"score":54.6,"unitPrice":19.99,"quantity":3,"total":59.97}

Supported functions

  • nullable, optional, cardinality, and unique: bool, bytes, string, int, float, faker, uuid, ulid, uniform, normal, and oneOf.
  • nullable and optional only: easing and easingChain.
  • round: float, uniform, normal, add, subtract, multiply, divide, pow, min, max, sum, avg, easing, and easingChain.
  • min and max as named clamps: normal only.

Functions not listed for a modifier reject it during validation.

Next: calculate numeric values.