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 |
Documentation
Section titled “Documentation”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}, whereconditionis the condition of a match, andvalueis the destiny data to map the input to, or transform to apply on top of input data
Matching Rules:
- [For dict based conditions only] Input is first converted to string before matching
- Exact matches are checked first (case-sensitive)
- If no exact match, regex patterns (prefixed with ‘RE:’) are checked
- Regex matches are checked in the order they appear in the table
- 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 |
Examples
Section titled “Examples”Basic value mapping - against condition map
Section titled “Basic value mapping - against condition map”Input args: ["true"]Transforms: "valuemap:{\"true\":1,\"false\":0}"Output: 1Basic 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: 1Basic 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"Mixed type matching - bool maps to string
Section titled “Mixed type matching - bool maps to string”Input args: [true]Transforms: "valuemap:{\"true1\":1,\"False\":0,\"42\":\"forty-two\"}"Output: 1Mixed 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"Regex matching - digits
Section titled “Regex matching - digits”Input args: ["123"]Transforms: "valuemap:{\"RE:^\\\\d+$\":\"number\",\"RE:^[a-z]+$\":\"letters\"}"Output: "number"Regex matching - letters
Section titled “Regex matching - letters”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"Combined exact and regex - regex match
Section titled “Combined exact and regex - regex match”Input args: ["user1"]Transforms: "valuemap:{\"admin\":\"superuser\",\"RE:^user\":\"regular\"}"Output: "regular"