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.
Assigning a literal value to data type any
"Hello!"
Assigning an object value to an object or data type any
{ "Author": "Martin Fowler", "ISBN": "0-321-12742-0", "Price": "$45" }where "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 below for details on how to use a function.
Assigning an array value to an object or 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 below 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) will be 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. In other words, there will be 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"
where $flow is the scope within which isbn falls.
- An object: When assigning an object, you must create a
mapping node within the object. The
mapping node is used to define how the object should be constructed and the various fields within the object mapped. For example, to assign the
bookDetails 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 below 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 are 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": "BookTile", "price": 19.8 } ] } }
In the example above books is an array of two elements. The values of each property for both elements are provided.
You can use a function instead of a literal value when assigning values for each element. See the "Using a function" section below for details on how to use a function.
- Building an Array from an upstream output array
In the following example, books is an of an array of books coming from the upstream output. To iterate over the array, $fow.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 which store.books falls and $loop represents the scope for each property within the object. Refer to the following section for details on the forEach() 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 public
petstore service. The mapper uses the
string.concat function and assigns the function return value to the
description field in the
data 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 type param. 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" } }