Object

Construct

Constructs an object with values stored at input keys.

Inputs

  • *User-Defined*: This input object will contain the schema that you want your constructed object to be set to. See example for more information.

Outputs

  • output: The constructed object.

Example

This will be one of your most-used modules in Forge. This module will help you shape data into the forms you need- which is often used to render data into the format needed to display your Connector in the Designer. In this example, you’ll see the desired object shape and how one would declare this shape in the Object.Construct module.

{
  "brick": "object.construct",
  "id": "12345",
  "inputs": {
    "Example Top Level Object" : {
      "InnerObject" : {
        "Key" : "{{reference to a value here}}"
      }
    }
  },
  "outputs": {
    "output": {
      "_type": "object",
      "_array": false
    }
  }
}

Resulting object:

{
  "Example Top Level Object" : {
    "InnerObject" : {
      "Key" : "resulting value"
    }
  }
}

Filter

Filter empty values from an object and return the new object.

Inputs

  • object: The object that you would like to filter keys with empty values out of.

Outputs

  • output: The object that no longer has keys with empty values.

Get

Reads the value stored in an object at a given path, with embedded paths delimited by a dot.

Inputs

  • object: The object that you would like to grab a value from.
  • path: The path that you would like to grab the value from within the given object.

Outputs

  • output: The value at the given path within the given object.

Pick

Build a new object by picking select values from another object.

Inputs

  • object: The object that you would like to pick objects from.

Outputs

  • *User-Defined*: The items you would like to pick out from the given object. You must define which items you would like to have be output from this function. See example for details.

Example

To use this module, you need to choose the object that you would like to pick from first. After this, choose the keys you would like to put into a new object by defining them in this module’s “outputs” section. You must define the appropriate type and collection state of each key, in accordance with that key’s type/state.

{
    "brick": "object.pick",
    "id": "IDHere",
    "inputs": {
        "object": {
            "_type": "object",
            "_array": false,
            "_value": "{{object.name}}"
        }
    },
    "outputs": {
        "pathName1": {
            "_type": "<insert the type of this path's value here>",
            "_array": "<insert true if this path's value is a collection, false otherwise>"
        },
        "pathName2": {
            "_type": "<insert the type of this path's value here>",
            "_array": "<insert true if this path's value is a collection, false otherwise>"
        }
    }
}

Process

Builds a new object by performing a Flow over each key inside of a given object.

Inputs

  • object: The object you would like to process
  • flo: The Flow that will handle the processing of your object
  • concurrency: The concurrency at which your sub-Flow will operate at over the items inside the provided object.

Outputs

  • output: The resulting, processed object.

Example

Here’s an example method that will perform an operation on both the key and value for each item inside of an object. In this case, the end goal is to go over each key and increment its corresponding value, and to append that new value onto the key’s name. If our starting list is:

{  "key": 1,  "key2": 2,  "key3": 3  }  

Then the ending list will be:

{  "key2" : 2,  "key3" : 3,  "key4" : 4  }

Defining the actual process brick is fairly straightforward:

{
    "brick": "object.process",
    "id": "ryEhp",
    "inputs": {
        "object": {
            "_type": "object",
            "_array": false,
            "_value": {
                "key": 1,
                "key2": 2,
                "key3": 3
            }
        },
        "flo": {
            "_type": "flo",
            "_array": false,
            "_value": "addOne"
        },
        "concurrency": {
            "_type": "number",
            "_array": false,
            "_value": 1
        }
    },
    "outputs": {
        "output": {
            "_type": "object",
            "_array": false
        }
    }
}

Setting up your processing sub-Flow (in this case, called “addOne”) is key to getting this to work properly. The method that will iterate over this list contains two modules, add and construct, which accomplishes the actual goal of our method. These work the same as any metadata method with a variant (like List.map), with the exception how we declare the variant.

There are two variant values in this case, the key and the value. In map, we’re used to using just one value called key, but with Object.process, we need to be able access both the key and the value. To enable this, you now declare both in a variant array, that contains both key and value. You can then refer to these values within the core array for that metadata method.

{
    "name": "addOne",
    "description": "No description provided.",
    "kind": "metadata",
    "variant": [
        {
            "_key": "key",
            "_type": "string",
            "_defaultValue": ""
        },
        {
            "_key": "value",
            "_type": "number",
            "_defaultValue": 0
        }
    ],
    "zebricks": [
        {
            "brick": "math.add",
            "id": "add",
            "inputs": {
                "a": {
                    "_type": "number",
                    "_array": false,
                    "_value": "{{value}}"
                },
                "b": {
                    "_type": "number",
                    "_array": false,
                    "_value": 1
                }
            },
            "outputs": {
                "output": {
                    "_type": "number",
                    "_array": false
                }
            }
        },
        {
            "brick": "object.construct",
            "id": "r1Yc0",
            "inputs": {
                "key": "{{key}}",
                "value": "{{add.output}}"
            },
            "outputs": {
                "output": {
                    "_type": "object",
                    "_array": false
                }
            }
        }
    ]
}

If you wanted to do this inline, you would instead declare “item” as an array in the parent module, like so:

"item": ["key", "value"]