How to write jq runtime expressions
Write expressions as ${ ... }. Start with current task input ., move through fields with jq, and use pipes to break a transformation into steps.
Read and transform input
The following workflow builds an output from an array of order lines. The fallback after add handles an empty array.
To run the examples, complete the SQLite setup and keep its worker running. Run the commands from a second terminal in the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. Save the definition as aggregate-order-data.yaml:
Expect {"orderId":"ORD-801","total":30,"itemCount":2}, then {"orderId":"ORD-802","total":0,"itemCount":0} for the empty order.
Keep data between tasks
Use $context for earlier values exported by a task and $workflow.input for the input supplied when the instance started.
Save it as share-order-context.yaml:
The second task no longer sees the customer in its input, but reads it from $context: expect {"orderId":"ORD-803","customerId":"C-100"}.
Check an expression with local data
Use the jq command-line tool on a small sample with the shape you expect the task to receive. Pass the expression inside ${ ... } to jq as its filter.
It prints 25. Lemline evaluates expressions with a Java implementation of jq, so check functions that are new in recent jq versions in a workflow too.
See Runtime Expressions for evaluation scopes and Debugging Workflows for logging task input.