string Functions

Use string functions in rules to manipulate text strings in asset JSON at runtime.

For instance, a string function can replace all occurrences of one string with another or convert strings from uppercase to lowercase. If a user enters a dashboard title in the wizard using all lowercase letters, the string function changes the text to sentence case at runtime.

toUpperCase 

Parameters: Object

Returns: Object

Recursive: Supported

Description: Converts all characters in an object to uppercase. The object can be a single string or a JSON object with multiple strings

Example 

This JSON

1"objecttest" : {
2        "obj" : {
3            "greeting1" : "hello world",
4            "greeting2" : "salut world",
5            "greeting3" : "hallo world"
6        },
7        "list" : ["hello world", "salut world", "hallo world"]
8    },

And the rule:

1{
2    "action": "set",
3    "description": "Convert all strings to upper case",
4    "path": "$.objecttest",
5    "value" : "${string:toUpperCase(Rules.CurrentNode)}"
6}

Returns:

1"objecttest" : {
2        "obj" : {
3            "greeting1" : "HELLO WORLD",
4            "greeting2" : "SALUT WORLD",
5            "greeting3" : "HALLO WORLD"
6        },
7        "list" : ["HELLO WORLD", "SALUT WORLD", "HALLO WORLD"]
8    },

toLowerCase 

Parameters: Object

Returns: Object

Recursive: Supported

Description: Converts all characters in a string to lowercase.

replace 

Parameters: Object obj, String oldStr, String newStr

Returns: Object

Recursive: Supported

Description: Returns a new object with all occurrences of oldStr replaced with newStr.

replaceAll 

Parameters: Object obj, String regex, String newStr

Returns: Object

Recursive: Supported

Description: Replaces all substrings of this string that match the given regular expression.

replaceFirst 

Parameters: Object obj, String regex, String newStr

Returns: Object

Recursive: Supported

Description: Replaces the first substring of this string that matches the given regular expression.

split 

Parameters: Object obj, String regex

Returns: Object

Recursive: Supported

Description: Parses a string and splits it into an array defined by the specified delimiter. For example:

1${string:split('one:two:three', ':')}

Results in array of strings:

1['one','two','three']

If more complex regular expression matching is required, use match (next).

match 

Parameters: Object obj, String regex

Returns: Object

Recursive: Supported

Description:

Performs complex regular expression matching and returns an array of matching results. For example, to capture items surrounded by square single quote and square brackets:

1${string:match('['foo']['bar']['baz']', '\\\\[\\'(.*?)\\'\\\\]')

Returns the following array:

1foo

2bar
3baz

join 

Parameters: Object obj, String delimiter

Returns: Object

Recursive: Supported

Description: Creates a string from an array of strings and separates each item by the specified delimiter.

1${string:join(<string>, <delimiter>)}