Set Variable: operations
Operations let you modify variables in ways that were previously only available through the use of advanced metadata. See the table below of the transformations available in the Set Variable behavior.
Available operations
Operation | Operators | Description |
---|---|---|
Add | Operand: Integer | Add the value of an operand to the variable. The transformation could fail if either of the input values are not integers. |
Base 64 Encode | Apply base64 encoding to a variable. | |
Base 64 Decode | Decode a base64-encoded string. | |
Base 32 Encode | Apply base32 encoding to a variable. | |
Base 32 Decode | Decode a base32-encoded string. | |
Bitwise AND | Operand | Perform a bitwise-and operation on the variable and an operand. This transformation could generate an error if either of the inputs is not an integer. |
Bitwise NOT* | Perform a bitwise-not operation on the variable. This transformation could generate an error if the input is not an integer | |
Bitwise OR | Operand | Perform a bitwise-or operation on the variable and an operand. This transformation could generate an error if either of the inputs is not an integer. |
Bitwise-XOR | Operand | Perform a bitwise-xor operation on the variable and an operand. This transformation could generate an error if either of the inputs is not an integer. |
Decimal To Hex | Convert a decimal integer to a hexadecimal string. This transformation could generate an error if the input is not an integer. | |
Decrypt | Algorithm: Picklist Encryption Key: String Initialization Vector: String Encryption Mode: Picklist Nonce: String Prepend Bytes: On/Off | Decrypt an encrypted string.
|
Divide | Operand | Divide the variable by the value of an operand. This transformation could generate an error if either of the inputs is not an integer or if the value of the operand is zero (0). |
Encrypt | Algorithm: Picklist Encryption Key: String Initialization Vector: String Encryption Mode: Picklist Nonce: String Prepend Bytes: On/Off | Encrypt the variable. The output is the nonce followed by the base-64 encoded encrypted input.
|
Epoch to String | Format String | Transform a value taken to be in epoch time,
int strftime format, into
RFC2616 format or other user specified format. See also, string-to-epoch for the reverse transformation. |
Extract Parameter | Parameter Name: String Separator: Character Case Sensitive: On/Off | Extract a value from a list of parameters.
A use case for this is to extract query parameters without having to write a regular expression, but it can be used to look up values in any name/value pair list. If several occurrences of the parameter exist, only the first one is returned. If the parameter is not found, the transformation fails and the variable gets a blank value. The separator between the name and the value of a parameter is always '=', but the parameter separator can be specified. Example: Value (lookup table) = |
Hash | Min: Integer Max: Integer | Hash the input string into an integer. This returns the string representation of
(HASH(input) % (max-min+1)) + min , where HASH is an arbitrary function that hashes a string into an unsigned 32-bit integer. |
Hex to Decimal | Convert a hexadecimal string to a decimal integer. | |
JSON extract | Operand | Extract JSON data from the variable using the XPath expression you formed in an operand. For more details on the expression's syntax, see JSON extract expression examples. |
Hex Decode | Decode a hex-encoded string. | |
Hex Encode | Encode input as hex-encoded string. | |
HMAC | HMAC Key: String HMAC Algorithm: Picklist | Produce a base64 encoded digest value from the variable value and key. |
Lower Case | Convert the string to lower case. | |
MD5 Hash | Obtain the MD5 of the value provided in one of the attribute tags ( or ) or of the value of the
assign:variable.value tag if none of the attribute tags is used. (This is backward-compatible with the behavior before the attribute tags existed.) If at least one parameter is provided, the md5 is performed on the parameters in the order in which they are provided. The transformation obtains the MD5 as a hexadecimal string of size 32 in uppercase. | |
Minus | Transform the value into a negative value. | |
Modulo | Operand | Return the remainder of division of the value with an operand. This transformation can fail if either of the input values is not an integer or if operand is zero (0). |
Multiply | Operand | Multiply the value of an operand with the variable. The transformation could fail if either of the input values are not integers. |
Normalize Path Windows | Remove multiple slashes, self-references, and directory back-references. | |
Remove Whitespaces | Remove all whitespace characters. | |
Compress Whitespace | Convert whitespace characters to spaces, then compress multiple space characters into only one. | |
SHA1 | Calculate an SHA1 hash from the value.
| |
SHA256 | Calculate an SHA256 hash from the value.
| |
String Index | Substring: String | Returns the position of the first occurrence of a substring inside the input string, or -1 if it is not found. This comparison is case sensitive. This operation never fails, it simply returns -1 when the substring is not found. |
String Length | Returns the string length of the input variable. | |
String to Epoch | Format String: String | Convert a string value from strptime format, or a custom defined format, into epoch time. You can specify the format of the string-to-epoch transformation. If no value is specified, or the if is set to RFC2616, the format of the input string is interpreted as RFC2616 format. You can specify a custom format using strftime variables. See the strftime(3) man page for proper format variables:
https://www.linux.com/learn/docs/man/4184-strftime3 |
Substitute | Regex: String Replacement: String Case Sensitive: On/Off Global Substitution: On/Off | Perform a regular expression-based substitution (similar to Perl's =~ s/regex/replacement/flags). Specify the regex, replacement string and global+case-sensitive options. |
Substring | Start Index: Integer End Index: Integer | Extracts a substring from the input variable/value. The start index is the position of the first character of the desired substring (0 for first character, 1 for second character, etc.). Negative values are relative to the right side of the input string. The end index is the position of the character after the end of the desired substring. -1 represents the last character of the string.
Consider this example for a string of Start Index = 0 , End Index = 1, Result = Start Index = 0 , End Index = 2, Result = Start Index = 1 , End Index = 1, Result = Start Index = 1 , End Index = 2, Result = Start Index = 3 , End Index = -1, Result = Start Index = -2, End Index = -1, Result= |
Subtract | Operand | Subtract the value of an operand from the variable. The operation could fail if either of the input values are not integers. |
Trim | Removes leading and trailing white spaces from the input. | |
Upper Case | Convert the input to upper case characters. | |
Base 64 URL Decode | The same as Base 64 Decode, except before decoding replaces + with - and / with _ . If due to the encoding there are not enough characters for the algorithm, this adds = characters at the end of the string. For more information, see: https://en.wikipedia.org/wiki/Base64#Output_padding | |
Base 64 URL Encode | The same as Base 64 Encode, except after encoding this removes trailing = characters, replacing + with - and / with _ . | |
URL Decode | URL decode the variable. All sequences of '%' followed by 2 hexadecimal characters are replaced with the corresponding ASCII value. The sequence '%%' is replaced with '%'. The sequence '%00' causes the transformation to fail, since the value of a variable is a null-terminated string and therefore cannot contain any null characters.
| |
URL Encode | Except Chars: String Force Chars: String | URL encode the variable. All characters deemed unsafe or reserved by RFC 1738 are escaped. That is, they are replaced with '%' followed by their 2-character hexadecimal value.
Unsafe characters are: ASCII characters between |
URL Decode Unicode | URL decode the variable value, including unicode encoding. All sequences of '%' followed by 2 hexadecimal characters are replaced with the corresponding ASCII value. The sequence '%%' is replaced with '%'. The sequence '%00' causes the transformation to fail, since the value of a variable is a null-terminated string and therefore cannot contain any null characters.
| |
UTC Seconds | Convert a string in ISO 8601 time format to UTC seconds. | |
XML Decode | XML-decode the variable value. This operates in the reverse of XML Encode. Invalid entities cause the operation to fail. | |
XML Encode | XML-encode the variable value. Characters < |
Combining operations
To use more than one transformation on a variable, use multiple Set Variable behaviors in the rule. The order matters when setting the different transformations, and the transformations are applied in the order they appear in the rule. After the first transformation, any subsequent instance of the Set Variable behavior must have that variable selected as were the value is coming from. You can string as many transformations together as you want.
Set Variable only allows one transformation per instance of the behavior. If you require multiple transformations for a variable, use multiple Set Variable behaviors.
For example, if you want to retrieve the first two characters of a variable's value, then change those two characters to uppercase. To do this you would need two instances of the Set Variable behavior; one to change the case of the value, and the other to retrieve the first two characters from that same value.
This is how you would accomplish this task:
How to
-
Add the first instance of Set Variable.
-
Select the variable you want to transform.
-
Select Extract as the source of the value.
-
Select Request Header.
-
Enter the name of the header to take the value from.
-
Select Upper Case transform.
-
-
Add a second Set Variable behavior.
-
Select the same variable.
-
Create value from expression.
-
Add the variable as the expression value.
-
Select sub-string as your transformation.
-
Start index of 0.
-
Max index of 1.
-
JSON extract expression examples
The expression's syntax is based on XPath. While XPath is designed to query XML data, it also works for simpler JSON data structures. References to arrays yield values concatenated as a string. References to objects yield concatenated values of all the object's keys. References to multiple keys via a wildcard yields space delimited concatenated values.
Consider these examples of expressions and the values they extract:
JSON file | Operand expression | Extraction |
---|---|---|
{ "store": { "book": { "category": "reference", "author": "John Doe", "title": "Sayings of the Century", "price": 8.95 }, "bicycle": { "color": "red", "price": 19.95 } } } | /store/book/author | John Doe |
{ "store": { "book":[ { "category": "reference", "category": "fiction"} ], "bicycle": { "color": "red", "price": 19.95 } } } | /* | referencefictionred19.95 |
{ "store": { "book":[ { "category": "reference", "category": "fiction"} ], "bicycle": { "color": "red", "price": 19.95 } } } | /store/book/* | referencefiction |
{ "store" : { "bicycle": { "color": "red", "price": 19.95 } } } | /store/bicycle/color | red |
{ "name": [ "value1", "value2" ] } | /name | value1value2 |
{ "name1":"value1", "name2":"value2"} | /* | value1 value2 |
[ "value1", "value2" ] | /* | value1 value2 |
[ true, false, null, 123 ] | /* | true false null 123 |
{"ID":null,"name":"Doe","first-name":"John","age":25,"hobbies":["reading","cinema",{"sports":["volley-ball","badminton"]}],"address":{}} | /hobbies | readingcinemavolley-ballbadminton |
{"ID":null,"name":"Doe","first-name":"John","age":25,"hobbies":["reading","cinema",{"sports":["volley-ball","badminton"]}],"address":{}} | /hobbies/*/sports | volley-ballbadminton |
{"Image":{"Width":800,"Height":600,"Title":"View from 15th Floor","Thumbnail":{"Url":"http://www.example.com/image/481989943","Height":125,"Width":100},"Animated":false,"IDs":[116,943,234,38793]}} | /Image/Thumbnail | http://www.example.com/image/481989943125100 |
Updated 12 months ago