Clean Object Operator
Overview
When working with a Data Workflow, there are times you might want to clean up a data object. This is because API (application programming interface) endpoints can be sensitive about defined field types. For example, an API call could fail if an endpoint receives a data type it wasn't expecting. So, to ensure you're sending the API data it can process, you'll use the Clean Object operator to convert any unwanted data types. Using this operator, there are 3 ways you can clean a data object:
-
Omit Null: Completely removes any fields with a null value.
-
Set Null to Empty String: Converts all null values to empty strings (empty strings look like "").
-
Convert All to String: Converts all values to strings.
All of these action types clean up the entirety of the data object, including any nested objects.
You'll find the Clean Object operator under the Object group to the left of your canvas.
What You'll Learn
In this article, you'll learn:
About the Info Window
Here's what the operator looks like, along with its Info window:
And here's a breakdown of each setting in the Info window:
Setting |
Description |
---|---|
Category |
Grayed out and non-adjustable setting indicating the operation type. |
Label |
Sets the label for your operator. The label you enter here shows beneath your operator on your Data Workflow canvas. This field is optional, but set a label if you use more than one of the same operator type. A label helps you identify your operators without opening any Info windows. |
Clean Action |
Sets the type of action the operator performs. The 3 options are:
|
Adding a Clean Object Operator
To see how the Clean Object operator works, let's take a look at an example. First, you'll create a Data Table that holds some values. You'll also add a Data Workflow component whose sole purpose is to create null values. This lets you test the Clean Object operator to its fullest potential. For this use case, you'll use the Convert All to String action type. That way, you'll see the numbers and null values become strings.
Here's how the completed use case will look in the Module Builder:
Here's how the completed use case will work in Express View, including a peek at the DevTools Console:
What You'll Need
To set up this use case, you’ll need:
To set up your Data Workflow, you'll need:
Configure the Data Table Component
First, you'll set up a Data Table with companies and their values.
1. | In the Module Builder, drag and drop a Data Table component onto your canvas. |
2. | Enter dtSampleData in the Label and Property Name fields. |
3. | In the data table, enter the following: |
value |
company |
---|---|
12 |
Unqork |
34 |
Cvent |
56 |
Trustpilot |
78 |
BetterWorks |
90 |
J.P. Morgan |
4. | Click Save. |
Configure the Hidden Components
Before you can add your Data Workflows, you'll need places to store their outputs. You'll use 2 Hidden components, one for each Data Workflow.
1. | Drag and drop 2 Hidden components onto your canvas, placing them below your Data Table. |
2. | Enter the following Property IDs and Canvas Label Text: |
Property ID |
Canvas Label Text |
---|---|
dataWithNullValues |
dataWithNullValues |
allStrings |
allStrings |
3. | Save each component as you add it. |
Configure the First Data Workflow Component
1. | Drag and drop a Data Workflow component onto your canvas, placing it below your Hidden components. |
2. | Enter dwfCreateNullValues in the Canvas Label Text and Property Name fields. |
Configure the Input Data Operator
1. | Drag and drop an Input operator onto your Data Workflow canvas. |
2. | Configure the Input operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Input |
Component |
dtSampleData |
Required |
Yes |
Source |
Default |
Configure the Create Field Operator
This operator is going to add an extra value to the data. Now, each object includes a testField with the value of null.
1. | Drag and drop a Create Field operator onto your Data Workflow canvas. |
2. | Configure the Create Field operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Formula |
Label |
Create Test Field |
Do Not Sanitize Formula |
Checked (Yes) |
Field 1 |
testField=NULL |
Field 2 |
|
Field 3 |
|
Field 4 |
|
Field 5 |
|
3. | Connect the output port (right) of the Input operator to the input port (left) of the Create Field operator. |
Configure the Output Operator
1. | Drag and drop an Output operator onto your Data Workflow canvas. |
2. | Configure the Output operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Output |
Component |
dataWithNullValues |
Action |
value |
3. | Connect the output port (right) of the Create Value operator to the input port (left) of the Output operator. |
4. | Click Save. |
Configure the Second Data Workflow Component
1. | Drag and drop another Data Workflow component onto your canvas, placing it below your other Data Workflow. |
2. | Enter dwfCleanObject in the Canvas Label Text and Property Name fields. |
Configure the Input Data Operator
1. | Drag and drop an Input operator onto your Data Workflow canvas. |
2. | Configure the Input operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Input |
Component |
dataWithNullValues |
Required |
Yes |
Source |
Default |
Configure the Clean Object Operator
This operator is going to convert all the values from the dataWithNullValues
1. | Drag and drop a Clean Object operator onto your Data Workflow canvas. |
2. | Configure the Clean Object operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Clean Object |
Label |
Convert to String |
Clean Action |
Convert all to String |
3. | Connect the output port (right) of the Input operator to the input port (left) of the Clean Object operator. |
Configure the Output Operator
1. | Drag and drop an Output operator onto your Data Workflow canvas. |
2. | Configure the Output operator's Info window as follows: |
Setting |
Value |
---|---|
Category |
Output |
Component |
allStrings |
Action |
value |
3. | Connect the output port (right) of the Clean Object operator to the input port (left) of the Output operator. |
4. | Click Save. |
5. | Save your module. |
Now it's time to test your Data Workflow! Preview your module in Express View and then open the DevTools Console. You'll see the number and null values are both strings now.
Changing a Clean Object Operator's Settings
You can revisit and make changes to this operator.
1. | Click the Data Workflow component. |
A 5-button toolbar displays above the component on hover-over.
2. | Click the (Settings) button to open the Data Workflow canvas. |
3. | Click the operator to open its Info Window. |
4. | Make changes to the operator's settings as needed. |
5. | Click Save. |
6. | Save your module. |
Copying a Clean Object Operator
You can make a copy of your operator using familiar keyboard settings. You can copy and paste an exact copy of your operator, matching all settings.
1. | Hover over the Data Workflow component. |
A 5-button toolbar displays above the component on hover-over.
2. | Click the (Settings) button to open the Data Workflow canvas. |
3. | Click the operator you want to duplicate. |
4. | On your keyboard, press Command + C (Mac OS) or Ctrl + C (Windows/Linux) to copy the operator. |
You can copy more than one operator at a time. Hold Command or Ctrl on your keyboard and click all the operators you want to copy. Follow the rest of the steps as usual.
5. | On your keyboard, press Command + V (Mac OS) or Ctrl + V (Windows/Linux) to paste the copied operator(s) to the Data Workflow canvas. |
6. | Click Save. |
7. | Save your module. |
Did you know you can copy an operator and paste it into a different Data Workflow? You'll use the same steps outlined above.
Removing a Clean Object Operator
Lastly, you can delete this operator from your Data Workflow canvas. You can also use these same steps to delete a connection between two operators.
1. | Hover over the Data Workflow component. |
A 5-button toolbar displays above the component on hover-over.
2. | Click the (Settings) button to open the Data Workflow canvas. |
3. | Click the operator you want to delete. |
4. | On your keyboard, press Delete. |
Once you delete this operator, make sure to connect your remaining operators. If your Data Workflow path doesn't end with an Output or Console operator, your Data Workflow won't work. So, once you delete an operator, make sure to update any remaining paths to end at an Output or Console operator.
5. | Click Save. |
6. | Save your module. |
Lab
You can view this complete use case here: https://training.unqork.io/#/form/6058ef1975657f0373bd5da5/edit.