Skip to content

valuemap

Written as valuemap(argnum flags):options in a transform expression.

Minimum arguments 1
Maximum arguments 1
Default arguments 1
Argument modes SINGLE_PRIMITIVE, SINGLE_ARRAY, SINGLE_DICT

Perform value mapping using a JSON configuration table with exact and regex matching.

This transform maps input values to specified outputs using a JSON mapping configuration. It supports both exact matches and regular expression patterns, with regex matches having lower priority than exact matches.

The JSON mapping configuration supports 2 forms:

  • dict: keys as conditions of match for input data, keys as the condition to match on input data’s string representation, values as the destiny data to map the input to, or transform to apply on top of input data
  • list: each item in the list must be a json dict per this format: {"condition": any, "value": any}, where condition is the condition of a match, and value is the destiny data to map the input to, or transform to apply on top of input data

Matching Rules:

  1. [For dict based conditions only] Input is first converted to string before matching
  2. Exact matches are checked first (case-sensitive)
  3. If no exact match, regex patterns (prefixed with ‘RE:’) are checked
  4. Regex matches are checked in the order they appear in the table
  5. If no matches found, original input is returned

Notes:

  • The JSON table must be properly formatted (quoted keys/values)
  • Regex patterns use Python’s re.match() (anchored at start of string)
  • For regex patterns, only the first matching pattern is used
  • Returns original value if no matches found
  • For dict based conditions, numeric/boolean values are converted to strings before matching
  • this transform only handles simple mapping from a source data object to a destiny data object per rules in the JSON mapping configuration. It’s not best suited for transforming JSON dict/array objects (in which case, ‘KeypathTransform’ or ‘JMESpathTransform’ should be used instead).
Flag Letter
spread_output S
noncaptive_input I

Basic value mapping - against condition map

Section titled “Basic value mapping - against condition map”
Input args: ["true"]
Transforms: "valuemap:{\"true\":1,\"false\":0}"
Output: 1

Basic value mapping - against condition list

Section titled “Basic value mapping - against condition list”
Input args: ["true"]
Transforms: "valuemap:[{\"condition\":\"true\", \"value\":1},{\"condition\":\"false\", \"value\":0}]"
Output: 1

Basic value mapping - no match returns unchanged

Section titled “Basic value mapping - no match returns unchanged”
Input args: ["other"]
Transforms: "valuemap:{\"true\":1,\"false\":0}"
Output: "other"
Input args: [true]
Transforms: "valuemap:{\"true1\":1,\"False\":0,\"42\":\"forty-two\"}"
Output: 1

Mixed type mapping - number maps to string

Section titled “Mixed type mapping - number maps to string”
Input args: [42]
Transforms: "valuemap:{\"True\":1,\"False\":0,\"42\":\"forty-two\"}"
Output: "forty-two"
Input args: ["123"]
Transforms: "valuemap:{\"RE:^\\\\d+$\":\"number\",\"RE:^[a-z]+$\":\"letters\"}"
Output: "number"
Input args: ["abc"]
Transforms: "valuemap:{\"RE:^\\\\d+$\":\"number\",\"RE:^[a-z]+$\":\"letters\"}"
Output: "letters"

Combined exact and regex - exact match takes priority

Section titled “Combined exact and regex - exact match takes priority”
Input args: ["admin"]
Transforms: "valuemap:{\"admin\":\"superuser\",\"RE:^admin\":\"regular\"}"
Output: "superuser"
Input args: ["user1"]
Transforms: "valuemap:{\"admin\":\"superuser\",\"RE:^user\":\"regular\"}"
Output: "regular"