jq expressions in workflows
Write a workflow expression as ${ ... }. Lemline evaluates expressions using jq. The current input is .. Use $workflow.input for the original input and $context for values exported by earlier tasks.
Object construction, arrays, filters and pipes are useful for selecting and reshaping data. This task counts items and computes the order total with map-style iteration and add.
document:
dsl: '1.0.3'
namespace: examples
name: aggregate-order-data
version: '1.0.0'
do:
- summarizeOrder:
set:
orderId: ${ .orderId }
total: ${ [.items[] | .quantity * .price] | add // 0 }
itemCount: ${ .items | length }
Compare values and branch
Use jq comparisons inside if or switch.when. A switch case without a condition provides a fallback.
document:
dsl: '1.0.3'
namespace: examples
name: validate-and-route-order
version: '1.0.0'
input:
schema:
format: json
document:
type: object
required: [orderId, total]
properties:
orderId:
type: string
total:
type: number
minimum: 0
do:
- routeOrder:
switch:
- largeOrder:
when: ${ .total >= 1000 }
then: requestReview
- automatic:
then: acceptOrder
- requestReview:
set:
status: needs-review
then: exit
- acceptOrder:
set:
status: accepted
output:
as: '${ { orderId: $workflow.input.orderId, status: .status } }'
Construct strings for integrations
Use jq string interpolation for dynamic URLs and @uri to escape values used in the path.
document:
dsl: '1.0.3'
namespace: examples
name: dynamic-http-endpoint
version: '1.0.0'
do:
- getProduct:
call: http
with:
method: get
endpoint: '${ "http://127.0.0.1:8787/products/\(.productId | @uri)" }'
See Runtime Expressions for other variables and Time in Workflows for timestamp comparisons.
Run the Examples
Every example on this page is a complete workflow. Complete the SQLite setup, save each example under the file name used below, and run the commands from the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline.
Start the tutorial shop from the root of the Lemline source checkout:
docker compose -f examples/tutorial-services/compose.yaml up -d
Keep the setup worker running and use a second terminal in the setup directory.
bin/lemline definition post -f aggregate-order-data.yaml
bin/lemline instance start examples aggregate-order-data --input '{"orderId":"ORD-801","items":[{"quantity":2,"price":12.5},{"quantity":1,"price":5}]}'
bin/lemline definition post -f validate-and-route-order.yaml
bin/lemline instance start examples validate-and-route-order --input '{"orderId":"ORD-302","total":1500}'
bin/lemline definition post -f dynamic-http-endpoint.yaml
bin/lemline instance start examples dynamic-http-endpoint --input '{"productId":"SKU-2"}'
Example | Expected result |
|---|
aggregate-order-data
| {"orderId":"ORD-801","total":30,"itemCount":2}
|
validate-and-route-order
| {"orderId":"ORD-302","status":"needs-review"}
|
dynamic-http-endpoint
| The watering can |
Stop the shop when you are done:
docker compose -f examples/tutorial-services/compose.yaml down
25 November 2026