Map

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).
  • <anyText>: A named value taken from the input key.

Map result example

This is an example based on the map displayed above. This code example show what are the events sent by the viewers:

[
  {"key": ["changeColor", "Aramis"], "value": "red"},
  {"key": ["changeColor", "Porthos"], "value": "green"},
  {"key": ["changeColor", "Porthos"], "value": "green"},
  {"key": ["changeColor", "Athos"], "value": "blue"},
  {"key": "cheer", "value": "Aramis"},
  {"key": "cheer", "value": "Porthos"},
  {"key": "cheer", "value": "Porthos"},
  {"key": "cheer", "value": "Athos"}
]

The map changeColor and cheer transforms them into the following:

[
  {"key": ["changeColor", "Aramis", "red"], "value": 1},
  {"key": ["changeColor", "Porthos", "green"], "value": 1},
  {"key": ["changeColor", "Porthos", "green"], "value": 1},
  {"key": ["changeColor", "Athos", "blue"], "value": 1},
  {"key": ["cheer", "Aramis"], "value": 1},
  {"key": ["cheer", "Porthos"], "value": 1},
  {"key": ["cheer", "Porthos"], "value": 1},
  {"key": ["cheer", "Athos"], "value": 1}
]