Build an output attribute with Multi-Attribute JQ
This guide shows you how to build an output attribute whose JQ function reads from several workflow attributes at once. Use it when a result depends on more than one value, so you no longer have to chain output attributes together to calculate it.
Before you begin
You should be comfortable adding an output attribute to a workflow. See Output Attributes.
You should know the basics of JQ. See Using JQ in a Workflow.
How it works
Until now, an output attribute’s JQ function could reference only a single value. If a result depended on several attributes, you had to chain multiple output attributes together to get there. Now, you add the attributes and actions you need to the output attribute, and each one gets a unique display name that you can edit. You then write one JQ function that references those display names.
When the Workflow evaluates the output attribute:
Alloy reads the live value of every attribute you referenced.
It combines those values into a single object.
It passes that object to your JQ function as input.
The function returns a single value, which becomes the output attribute’s result.
For example, if you add attributes with the display names monthly_income and monthly_debt, your JQ function receives an object shaped like this:
{
"monthly_income": 6200,
"monthly_debt": 1550
}
Default display names are added, but they're editable. Choose names that keep your JQ readable.
Build a Multi-Attribute JQ output attribute
Open the workflow and select the output attribute you want to edit, or add a new output attribute node.
In the output attribute panel, switch from Expression mode to Multi-Attribute JQ mode. This opens the Multi-Attribute JQ editing experience.
Add each action or attribute from the workflow that your function needs. Each one is assigned a unique display name that you can edit, however, the names must be unique.
Write your JQ function in the editor, referencing the display names you set. Your function must return a single value.
Save your changes.
Example: calculate a debt-to-income ratio
Suppose your workflow has two attributes, a monthly income and a monthly debt payment, and you want a single debt-to-income percentage.
After adding both attributes, enter:
if (.monthly_income // 0) > 0
then ((.monthly_debt // 0) / .monthly_income * 100 | round)
else null
end
The // 0 fallbacks and the if check keep the result well-defined when a value is missing or income is zero, so the function doesn’t divide by zero.
Before Multi-Attribute JQ, this calculation would have needed a chain of output attributes, with each one passing an intermediate result to the next.
Tips
Name attributes for the JQ, not the workflow. .monthly_income is easier to read and maintain than a long default name.
Plan for missing values. Use // to set a default, and check for zero before dividing.
Return one value. The function must produce a single result.
Test with fake data. When trying expressions in jq play, never paste real customer data.
