Map

Overview

The map function takes key:value pairs as input and transforms them into different key:value pairs when they meet defined criteria.

The output of the map function is the new set of key:value pairs.

This mapping forwards the same key:value if the key meets the defined pattern and if the value is a string in the list.

Map definition example

{
  "version": "1.7.0",
  "event": {
    "game": {
      "maps": [
        {
          "id": "changeColor",
          "source": "userinput",
          "where": {"key": ["changeColor", "<name>"], "name": "<color>", "type": "string"},
          "key": ["changeColor", "<name>", "<color>"],
          "value": 1
        },
        {
          "id": "cheer",
          "source": "userinput",
          "where": {"key": ["cheer"], "name": "<name>", "type": "string"},
          "key": ["cheer", "<name>"],
          "value": 1
        }
      ]
    }
  }
}

Map Schema

id

A unique string that refers to the map.

source

A string that indicates where the event originated. (Only “userinput” is currently supported.)

where

A schema defining the conditions that trigger producing a new key:value pair. See Where clause content for more information.

key

An array of strings representing the new key. Each string can be:

  • Alphanumeric string: A plain literal value.
  • <anyText>: A named value taken from the input key.

value

Specifies what value to assign for the value field after the map. Values produced by the map can be:

  • Alphanumeric string: A plain literal string value.
  • Number: Any numeric value.
  • Boolean: A boolean value (true or false).

Map Example

The Map function takes key:value pairs as input and transforms each into another key:value pair when they meet certain conditions. We refer to this as the Mapping step.

Genvid defines both the map and the transformation using a JSON file.

{
  "id": "playerlike",
  "source": "userinput",
  "where": {
    "key": [ "player", "like" ],
    "name": "<like>",
    "type": "string"
  },
  "key": ["like", "<like>"],
  "value": 1
}

In this example, when a key matching ["player", "like"] enters the system, it produces a new key:value pair. The new key becomes ["like", "$value"], where "$value" corresponds to the string value assigned to that key. The mapping step finishes by assigning “1” as the value of the transformed key.

For example, the following events come in from multiple viewers:

{ "key": ["player", "like"], "value": "player1" }
{ "key": ["player", "like"], "value": "player1" }
{ "key": ["player", "like"], "value": "player2" }
{ "key": ["player", "like"], "value": "player1" }

The map playerlike transforms them into the following:

{ "key": ["like", "player1"], "value": 1 }
{ "key": ["like", "player1"], "value": 1 }
{ "key": ["like", "player2"], "value": 1 }
{ "key": ["like", "player1"], "value": 1 }

Once the data is transformed, we apply the Reduce operation.