Skip to main content

Example approach: Data in, data out

In this article, we'll walk through how to transform data throughout your story builds.

Written by Yanni Hajioannou
Updated over a week ago

Overview

Whether you're just starting out or are an advanced builder in Tines, transforming your data throughout a story is vital to success. In this article, we cover some common methods using simple scenarios for restructuring event data within your stories to fit your needs.

Tines references

Before getting started, we recommend familiarizing yourself with the functionality this article covers:

Make it happen

Both sections below use the following array:

{
"items": [
{
"name": "Gala Apple",
"type": "apple"
},
{
"name": "Honeycrisp Apple",
"type": "apple"
},
{
"name": "Macintosh Apple",
"type": "apple"
},
{
"name": "Blueberry pie",
"type": "pie"
},
{
"name": "Raspberry pie",
"type": "pie"
},
{
"name": "Strawberry pie",
"type": "pie"
}
]
}

Loops and tags

In this video, we look at how to handle an incoming array and modify it to meet specific criteria.

The criteria in this scenario is to:

  • Add "is delicious" after every name key value where "pie" is mentioned (i.e., "Blueberry pie is delicious")

  • Capitalize the type key value

We enable a loop in our Event Transform action to cycle through each object within the items array. We then use an if tag and the INCLUDES function to iterate through each looped name key value to check if "pie" exists. If it does, we add the "is delicious" string to it. If it doesn't, we leave the name key value as is. We also use the CAPITALIZE function to capitalize the type key value.

An Event Transform action named "Format array" selected on the storyboard, highlighted with a red border, connected downstream from a Webhook action named "Catch Results." The Build panel on the right shows the action in message-only mode with Loop enabled. The Loop field is highlighted, set to catch_results.body.items. The Payload section is highlighted, showing the Builder view with two keys: name using an if tag that checks INCLUDES(LOOP.value.name, "pie") and appends "is delicious" if true, or returns the original name if false; and type using CAPITALIZE(LOOP.value.type).

We re-emit last event from the "Catch Results" action and see the results of our pie formatting in the events of the "Format array" action.

An Event Transform action named "Format array" with its event data panel open, showing the transformed array results. Three name values are highlighted with red borders: "Macintosh Apple" (unchanged, with type "Apple"), "Blueberry pie is delicious" (with type "Pie"), and "Raspberry pie is delicious" (with type "Pie"), demonstrating that the "is delicious" string was appended only to pie items and all type values were capitalized.

Organize event data

In this video, we look at how to take an incoming array and break it up based on a key identifier. In this example, we leverage the type key value of "apple" or "pie."

To create our categories (apple and pie), we use the explode mode of the Event Transform action. Since we only want to grab these specific values, we use the MAP and UNIQ functions to create a list array that includes one instance of each as the Explode Path.

An Event Transform action named "Explode 1 of each type" with its configuration panel open. The formula field on the left is highlighted, showing UNIQ(MAP(format_array,"type")) with the result ["Apple","Pie"] highlighted at the bottom. The Build panel on the right shows the Mode set to Explode (highlighted), the Path field set to the same UNIQ(MAP(format_array,"type")) formula (highlighted), and the To field set to individual_item.

This creates an event for each category. Now that they're established, you can organize the original array. Using the WHERE function in a subsequent Event Transform action, we compare the original array's type key values against the categories we created in the Explode to see if there are any matches.

An Event Transform action named "Capture type" with its configuration panel open. The formula field on the left is highlighted, showing WHERE(format_array,"type",explode_1_of_each_type.individual_item). The result preview is highlighted with a red border, displaying a filtered array of three pie items: "Blueberry pie is delicious," "Raspberry pie is delicious," and "Strawberry pie is delicious," all with type "Pie." The Build panel on the right shows the action in message-only mode with the Payload field containing the WHERE formula.

After re-emitting from a previous event, we can see how the final Event Transform action is showing only the pie results.

An Event Transform action named "Capture type" with its event data panel open. The capture_type array is highlighted with a red border, showing three filtered results: "Blueberry pie is delicious," "Raspberry pie is delicious," and "Strawberry pie is delicious," all with type set to "Pie."

Review the results

Mastering data transformation in Tines is key to building effective and efficient stories. By applying the methods outlined in this article, you can tailor your data structures to meet your specific requirements, improving the performance and clarity of your story flows.

Did this answer your question?