Builder

Allows powerful object creation via mapping, aggregating, and construction from conduit data.

The Builder Node is used for mapping data and building objects. It is a frequently used Node in Sanbox. With the Builder Node, you define a template model that is used to build an object.

Example

Consider the following Workflow:

In this example, we have a Gather Node that outputs this data:

{
"name": "John Smith",
"address": "32 Way St, Someplace, CO",
"orders": [
{
"productName": "Diabananic Diabetic Bananas",
"description": "Bananas for diabetics.",
"price": 30.00
},
{
"productName": "Inflatable Toast Mattress",
"description": "Toast now for breakfast and bedtime.",
"price": 194
}
]
}

We wish to modify this object slightly so that, for each order, our price is inside the description rather than its own property. We also want to add a dateModified property to our customer object with today's date. To achieve this, we configured our Builder Node as follows:

Builder Node Configuration

When you select a template model in the Builder Node, Sanbox Designer presents you with the model tree and a drop-down beside each property for where to populate the property. The following items in the drop-down are available:

Builder Source

Usage

Conduit

Uses a conduit to populate a property. Input is the source mapping.

Python

Uses a Python script to populate a property. The return of the Python script is populated into the property. NodeInput is the source mapping.

Function

Allows you to execute a Function Workflow who's output will populate the property. The conduit in this case is the input passed to the function.

Testing our above Workflow in Postman yields the following result:

Working With Objects and Arrays

Consider the following Builder Node configuration.

One thing to note about this configuration is that the billingDetails object property is initialized with an empty JSON object {}. If billingDetails is set to No Value the object will not be initialized and consequently the Builder Node will ignore all child properties of billingDetails.

The above configuration produces the following data...

{
"firstName": "Bob",
"lastName": "Billard",
"billingDetails": {
"addressLine1": "15 What St",
"city": "Some City",
"state": "CO"
}
}

More intuitively, the same behavior applies for arrays. If an array is not mapped or initialized then no children will be created for that array.

You can map anything to an array, if you map something that is not an array, its placed into one for the build.

In the above example, the object created will contain an array with each item within the users variable mapped. Consider the following value for the users variable:

[
{
"id": 12,
"firstName": "Bob",
"lastName": "Smith",
"loginDate": "2018-06-14T09:18:23.7081793"
},
{
"id": 5,
"firstName": "Kyle",
"lastName": "Smith",
"loginDate": "2018-03-14T09:18:23.7081793"
}
]

When the above build configuration runs, the following object is produced:

{
"collectionName": "allPeople",
"people": [
{
"firstName": "Bob",
"lastName": "Smith",
"lastLogin": "2018-06-14T09:18:23.7081793"
},
{
"firstName": "Kyle",
"lastName": "Smith",
"lastLogin": "2018-03-14T09:18:23.7081793"
}
]
}

When mapping arrays, the Builder Node creates your defined array type for each item in the array. The Input Conduit Source refers to the current item.

Primitives and Null Values

By default, the Builder Node will ignore properties that evaluate to null. You can check Include Null Values to have the builder node include the property regardless with its value set to null.

Checking the Auto-Convert Primitives box will convert primitives if needed. Say you had a property called age that is a number and pass in a string with the value 12. With this setting enabled the Builder will automatically convert the string to 12. Without the Auto-Convert Primitives box checked, an error is thrown in this case.