Skip to content

Object template

There are places where you may want to create an object that consist of the data from profile, payload, memory. etc. Is such cases you should use an object template. It will allow you to reshape the data into any object you want.

Here is an example of object template.

{
  "some-data": {
    "key": "value",  // This is static value
    "value": "profile@id"  // Reads value from profile and saves it in object new.value
    "list": [1, "payload@data"] // Reads data value from payload and saves it as 2nd element of list
    "event": "event@..."  // Saves in event all data from event.
  }
}

Notice that some parts of this object reference data with dot notation. The data will be replaced be the referenced data.

Let's assume that profile has the following data:

{
  "id": "profile-id",
  "data": {
    "name": "John",
    "age": 26
  }
}

And event equals:

{
  "type": "page-view",
  "properties": {
    "url": "http://localhost"
  }
}

then the result of the object template of:

{
  "some-data": {
    "key": "value",  // This is static value
    "value": "profile@id"  // Reads value from profile and saves it in object new.value
    "list": [1, "payload@data"] // Reads data value from payload and saves it as 2nf element of list
    "event": "event@..."  // Saves in event all data from event.
  }
}

will be:

{
  "some-data": {
    "key": "value",
    "value": "profile-id",
    "list": [
      1,
      {
        "name": "John",
        "age": 26
      }
    ],
    "event": {
      "type": "page-view",
      "properties": {
        "url": "http://localhost"
      }
    }
  }
}

Read also about related topics:


This documentation answers the following questions:

  • What is an object template?
  • When should you use an object template?
  • Can you reshape data into any object you want using an object template?
  • How to respond with JSON object that has data form profile
  • What is an example of an object template?
  • How do you reference data in an object template using dot notation?
  • What happens when you reference data in an object template using dot notation?
  • Can you provide an example of using an object template with sample data from profile and event?
  • How to create an object or JSON with data from profile, event, or session?