Get startedGet started for free

Transforming and Validating Data with Code Nodes

1. Transforming and Validating Data with Code Nodes

So far, we've been transforming data using Edit Fields — extracting fields, renaming them, and flattening structures. That works great for simple transformations. But what happens when we need to do something more complex?

2. From Edit Fields to Code

Maybe we need to calculate specific values or apply conditional logic to every item. That's where Code nodes come in. A Code node lets us run JavaScript or Python code directly inside our workflows. It takes the data from the previous node as input and returns the transformed data as output. To be clear about something — in this course, we're not going to write code from scratch. All the code will be provided for you. Your job is to run it, read it, understand what it does, and eventually make small changes. Think of it like reading a recipe before you start cooking. This may feel like cheating, but in fact, many practitioners today use AI tools to generate their initial Code node logic, then read and adjust it — which is exactly the skills you're building here. Let's see Code nodes in action!

3. Example: JavaScript Code Node

In this workflow, we have a Manual Trigger with three pinned weather records flowing into a Code node. Let's open the Code node. The first thing we see is a language selector — JavaScript or Python. Both languages can be used in the same way, and you'll try both in the exercises. Outside the course, choose whichever best matches your personal or organization's preferences. Below the selector is the code editor. For JavaScript, the input data arrives via $input.all(). This syntax gives us an array of all the items from the previous node. Each item has a json property containing its fields. The code processes these items and returns a new array as output. This JavaScript code takes our three weather records, pulls out just the fields we want, and adds a fetched_at timestamp. The .map() function runs the same transformation on every item — think of it as "do this to each item." The arrow is JavaScript's way of saying "take this item and return that result." We use $input.all() here because it works for both single and multiple items, but you may also see $input.first() in documentation, which returns just the first item when you know there's only one. Let's execute — the Output panel shows three transformed records with our clean fields and the new timestamp.

4. Example: Python Code Node

Now let's switch the language selector to Python and paste the equivalent code. Python works the same way, just with different syntax. Instead of a $ before input.all(), we use an underscore. And instead of returning an array of objects, it returns a list of dictionaries. The logic is identical — get the input items, transform them, and return the result. Another common piece of Python syntax is the .get() method, which is Python's safe way to read a field — if the field exists, it returns the value; if it doesn't, it returns an empty string instead of crashing. Again, you don't need to be a Python expert to read this, and you'll see similar patterns recurring over-and-over: loop through items, check conditions, and set a field. The Code node handles the execution — you just need to understand what the code is doing.

5. Let's practice!

Time to get your hands dirty!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.