Using Expressions in n8n
Desliza para mostrar el menú
Expressions in n8n let you dynamically customize data, automate decisions, and perform calculations within your workflows. An expression in n8n is written inside double curly braces, such as {{ $json["email"] }}. Expressions use JavaScript syntax, allowing you to reference and manipulate data from previous nodes, format values, and apply logic. For example, you might use an expression to insert a user's name from a previous step into an email template, or to calculate a value before passing it along to the next node.
Use expressions like {{ $json["firstName"] }} to pull in data from previous nodes.
Apply JavaScript date functions to format timestamps, such as {{ new Date($json["createdAt"]).toLocaleDateString() }}.
Return different values based on conditions, for example {{ $json["score"] > 80 ? "Pass" : "Fail" }}.
Suppose you have a node that outputs a user's details, and you want to create a personalized greeting. Before using an expression, your message might look like this: "Hello, user!". By adding an expression such as {{ $json["firstName"] }}, you can change the message to: "Hello, John!" if the firstName field is "John". You can also manipulate data, for instance, to combine fields: {{ $json["firstName"] + " " + $json["lastName"] }} results in "John Doe". This approach helps you tailor workflow outputs based on data flowing through your automation.
To test and troubleshoot expressions in n8n, use the "Execute Node" feature to run individual nodes and inspect their output. If an expression does not behave as expected, check for typos, ensure the referenced fields exist, and use the Expression Editor's preview to see real-time results.
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla