Languages
Learn about Languages in Laminar
Overview
Laminar supports both JavaScript and JQ for writing flow transformations. Each language has its own strengths and use cases.
JavaScript
JavaScript transformations use a simple function pattern:
(payload) => {
// Access data from previous steps or input
const { input, step_1 } = payload;
// Perform transformations
const transformed = {
// ... transformation logic
};
// Return result object
return {
"data": transformed,
// Optional Laminar keywords
"lam.httpRequest": {/*...*/}
};
}
Advantages
Familiar syntax for most developers
Rich ecosystem of npm packages
Native JSON handling
Powerful array/object manipulation
Example Transformation
(payload) => {
const { step_1 } = payload;
// Filter users who spent over $20
const highValueUsers = step_1.data.users
.filter(user => user.totalSpent > 20)
.map(user => ({
"lam.workflowId": 49,
"lam.payload": {
"lam.queryParams": {
"email": user.email
},
"lam.body": user
}
}));
return {
"lam.result": highValueUsers
};
}
JQ
JQ is a lightweight, powerful language specifically designed for JSON processing:
# Access input data using dot notation
.input |
# Transform using JQ operators
map(select(.totalSpent > 20)) |
# Output transformed data
{
"lam.result": .
}
Advantages
Concise syntax for JSON manipulation
Powerful built-in functions
Excellent performance for JSON processing
Native streaming support
Example Transformation
.step_1.data.users |
map(
select(.totalSpent > 20) |
{
"lam.workflowId": 49,
"lam.payload": {
"lam.queryParams": {
"email": .email
},
"lam.body": .
}
}
)
Choosing a Language
Choose JavaScript when:
You need complex business logic
Your team is more familiar with JavaScript
You want to use npm packages
You need advanced string/array operations
Choose JQ when:
You're primarily doing JSON transformation
You want concise, readable transformations
Performance is critical
You're working with streaming data
Last updated
Was this helpful?