Constructing the any, param, or object Data Type in Mapper
When mapping values for data type
any
or
object
, you must manually enter the values in the mapper text box.
Below are some examples of how to construct the data type
any
:
Assigning a literal value to data type any
To assign literal values to the
any
data type, you click on the element of type
any
, then simply enter the values you want to assign to it in the mapper text box. For example, to assign the string
Hello!
enter:
"Hello!"
Assigning an object value to an object or element of data type any
Here is an example of how to assign literal values to an object:
{ "Author": "Martin Fowler", "ISBN": "0-321-12742-0", "Price": "$45" }Here, "Author", "ISBN", and "Price" are the object properties. You can use a function instead of a literal value when assigning values for each element. See the "Using a function" section for details on how to use a function.
Assigning an array value to an object or data type any
Here is an example of how to assign an array value to an array of objects or to an element of data type
any
:
[ { "Author": "Martin Fowler", "ISBN": "0-321-12742-0", "Price": "$45" } ]
You can use a function instead of a literal value when assigning values for each element. See the "Using a function" section for details on how to use a function.
Assigning a value from the upstream output
When mapping to an element from the upstream output, the data type of the source element whose value you are assigning determines the data type of the destination element. For example, if you assign the value of an array, then the target element (the element of data type
any
) is treated as an array, likewise for a string, number, boolean, or object. For example, if you are mapping
$flow.Author
which is an array, then the Author object in the input (destination object) would also be an array. That is, there is a direct assignment from the source to the destination.
-
Single Element of Primitive Data Type: To assign the value of a single element of a primitive data type that belongs to the output of the trigger, a preceding Activity, or the flow input, you must enter the expression for it. For example to assign the value of
isbn
which comes from the flow input, enter the expression:"=$flow.isbn"
Here,
$flow
is the scope within whichisbn
falls. - An object: When assigning an object, you must create a
mapping
node within the object. Themapping
node is used to define how the object should be constructed and the various fields within the object mapped. For example, to assign thebookDetails
object, enter:{ "mapping": { "Author": "=$flow.author", "ISBN": "=$flow.name", "Price": 20, "BestSeller": true } }
You can use a function instead of a literal value when assigning values for each element. See the "Using a function" section for details on how to use a function.
- An array of objects: The following two examples show you how to assign values to arrays:
- Building a new array
To provide values for an array that has a fixed size (where the number of elements is declared), you must provide the values for each array element. For example, if the array has two elements, you must provide the values for each property of the object for both objects. Here is an example of how to do that:
{ "mapping": { "books": [ { "author": "=$loop.author", "title": "=$loop.title", "price": "=$loop.price" }, { "author": "Author2", "title": "BookTitle", "price": 19.8 } ] } }
In the example above
books
is an array of two elements. The values for each property for both elements are provided.You can use a function instead of a literal value when assigning values for each element. For details, see Using Functions.
- Building an Array from an upstream output array
In the following example,
books
is an array of books coming from the upstream output. To iterate over the array,$flow.store.books
in upstream output, and assign its values to the input array, you would enter the following in the mapper text box:{ "mapping": { "@foreach($flow.store.books)": { "author": "=$loop.author", "title": "=$loop.title", "price": "=$loop.price" } } }
The
"@foreach($flow.store.books)"
indicates that you are iterating an array of objects where the$flow.store.books
is the array.$flow
is the scope within whichstore.books
falls and$loop
represents the scope for each property within the object. Refer to the following section for details on theforEach()
function.
- Building a new array
- Using a function: The following example leverages the output of a REST Invoke Activity to get a
pet
from the publicpetstore
service. The mapper uses thestring.concat()
function and assigns the function return value to thedescription
field in thedata
structure:{ "mapping": { "data.description": "=string.concat(\"The pet category name is: \",$Activity[rest_3].result.category.name)" } }
Assigning Values to the param Data Type
When you import an app that was originally created in Project Flogo™, the app could contain elements that are of data typeparam
. The
param
data type is similar to the
object
data type in that it consists of key-value pairs. The difference between an
object
and a
param
is that the
object
can contain values of any data type whereas the values for elements in the
param
data type
must be of data type
string
only.
Here's an example of assigning values to a
param
data type element:
{ "mapping": { "Author": "=$flow.author", "ISBN": "=$flow.name", "Price": "$20" } }