TBEL Language Guide
This guide covers the TBEL syntax, data types, collections, and control-flow constructs. For the full list of built-in utility functions, see the Helper Functions reference.
Syntax constraints
Section titled “Syntax constraints”TBEL is based on MVEL. A few syntax rules differ from JavaScript:
- Use
foreachinstead offor...of/for...in. Traditionalforloops are also supported. - Ternary expressions must be wrapped in parentheses when used outside an explicit
ifstatement. - Multiple statements require semicolons; the semicolon after the final statement is optional.
Simple property expression
Section titled “Simple property expression”Access properties from context objects directly:
msg.temperatureBoolean expressions
Section titled “Boolean expressions”return (msg.temperature > 10 && msg.temperature < 20) || (msg.humidity > 10 && msg.humidity < 60);Standard operator precedence applies. Use parentheses to control execution order.
Multiple statements
Section titled “Multiple statements”Statements are separated by semicolons. The value of the last statement is the script’s return value:
var a = 2;var b = 3;a + b; // returns 5Type conversion
Section titled “Type conversion”TBEL automatically converts compatible types:
"123" == 123; // trueMaps are created inline and use a custom implementation with built-in memory tracking.
Creation
Section titled “Creation”var map = {"temperature": 42, "nested": "508"};Accessing values
Section titled “Accessing values”map.temperature // dot notationmap.get("temperature") // method callmap["temperature"] // bracket notationSafe-navigation prevents NullPointerException on missing keys:
if (map.?nonExistingKey.smth > 10) { }Iteration
Section titled “Iteration”Explicit entrySet():
foreach (element : map.entrySet()) { element.getKey(); // or element.key element.getValue(); // or element.value}Implicit (iterates over values):
foreach (value : map) { // process each value}Operations
Section titled “Operations”map.temperature = 0; // set valuemap.put("humidity", 73); // add entrymap.putIfAbsent("temperature1", 73); // add if missingmap.replace("temperature", 56); // replace valuemap.replace("temperature", 56, 42); // conditional replacemap.remove("temperature"); // remove entryvar keys = map.keys(); // get all keysvar values = map.values(); // get all valuesvar size = map.size(); // entry countvar memorySize = map.memorySize(); // memory in bytesmap.sortByKey(); // sort by key in-placevar sorted = map.sortByValue(); // sort by value in-placemap.putAll({"test": 12, "input": {"http": 130}}); // merge another mapisMap(map); // type check → trueUnmodifiable maps
Section titled “Unmodifiable maps”var original = {};original.humidity = 73;var unmodifiable = original.toUnmodifiable();unmodifiable.put("temperature1", 96); // throws error: Map is unmodifiableLists use a custom implementation with memory tracking. Only inline creation is permitted.
Creation and access
Section titled “Creation and access”var list = ["A", "B", "C"];list[0]; // "A"list.size(); // 3Iteration
Section titled “Iteration”foreach (item : list) { var smth = item;}
for (var i = 0; i < list.size; i++) { var smth = list[i];}Add operations
Section titled “Add operations”list.add(3, "thingsboard"); // insert at indexlist.push("thingsboard"); // append to endlist.unshift("r"); // prepend to startlist.addAll(["thingsboard", 4, 67]); // append all elementslist.addAll(2, ["x", "y"]); // insert all at indexRemove operations
Section titled “Remove operations”var removed = list.remove(2); // remove by indexlist.remove("C"); // remove by valuevar first = list.shift(); // remove and return firstvar last = list.pop(); // remove and return lastvar spliced = list.splice(3); // remove from index to endlist.splice(2, 2); // remove 2 elements at index 2list.splice(1, 4, "start", 5, "end"); // remove 4, insert replacementsModify operations
Section titled “Modify operations”list.set(3, "65"); // replace at indexlist[1] = "98"; // bracket assignmentlist.sort(); // ascending sort (default)list.sort(true); // ascendinglist.sort(false); // descendinglist.reverse(); // reverse in-placelist.fill(67); // fill entire listlist.fill(4, 1); // fill from index 1list.fill(2, 1, 4); // fill range [1, 4)Non-mutating operations
Section titled “Non-mutating operations”These return a new list without modifying the original:
var sorted = list.toSorted(); // new sorted list (ascending)var sortedDesc = list.toSorted(false); // new sorted list (descending)var reversed = list.toReversed(); // new reversed listvar sliced = list.slice(0, 2); // new sublist [0, 2)var replaced = list.with(1, 69); // new list with index 1 replacedvar merged = list.concat(otherList); // new concatenated listvar str = list.join(); // join elements into stringvar spliced = list.toSpliced(1, 0, "Feb"); // new list with splice appliedvar length = list.length();var memorySize = list.memorySize();var idx = list.indexOf("B", 1); // first index of "B" starting from 1list.validateClazzInArrayIsOnlyNumber(); // validate numeric contentisList(list); // type check → trueUnmodifiable lists
Section titled “Unmodifiable lists”var original = [];original.add(0x67);var unmodifiable = original.toUnmodifiable();unmodifiable.add(0x35); // throws error: List is unmodifiableSets are ordered collections that prevent duplicates.
Creation
Section titled “Creation”var set1 = toSet(["B", "A", "C", "A"]); // from list (3 elements — "A" deduplicated)var set2 = createSet(); // empty setvar set3 = createSet(["A", "B", "C"]); // from listvar set4 = newSet(); // empty setIteration
Section titled “Iteration”foreach (item : set) { // process item}
var arr = set.toArray();for (var i = 0; i < set.size; i++) { var item = arr[i];}Operations
Section titled “Operations”set.add(35); // add single element (returns true if new)set.addAll(otherSet); // merge another setset.remove(4); // remove elementset.clear(); // remove all elementsset.contains("A"); // membership check → true/falseset.size(); // element countset.toArray(); // convert to arrayset.toList(); // convert to listset.clone(); // shallow copyisSet(set); // type check → trueSorting
Section titled “Sorting”set.sort(); // ascending in-placeset.sort(true); // ascending in-placeset.sort(false); // descending in-placevar sorted = set.toSorted(); // new sorted set (ascending)var sortedDesc = set.toSorted(false); // new sorted set (descending)Unmodifiable sets
Section titled “Unmodifiable sets”var original = createSet();original.add(0x67);var unmodifiable = original.toUnmodifiable();unmodifiable.add(0x35); // throws error: Set is unmodifiableArrays
Section titled “Arrays”TBEL supports arrays only for primitive types. String indexing returns characters, and string arrays are automatically converted to lists.
var array = new int[3];array[0] = 1;array[1] = 2;array[2] = 3;
var str = "My String";var ch = str[0]; // 'M'
isArray(array); // trueCustom function example:
function sum(list) { var result = 0; for (var i = 0; i < list.length; i++) { result += list[i]; } return result;}var total = sum(array); // 6Literals
Section titled “Literals”Strings
Section titled “Strings”Single or double quotes:
"This is a string literal"'This is also string literal'Escape sequences: \\, \n, \r, \u#### (Unicode), \### (octal).
Numbers
Section titled “Numbers”125 // decimal integer0353 // octal0xAFF0 // hexadecimal10.503 // double94.92d // explicit double14.5f // float104.39484B // BigDecimal8.4I // BigIntegerBoolean and null
Section titled “Boolean and null”truefalsenullnil // alias for nullUsing Java classes
Section titled “Using Java classes”TBEL allows limited use of Java classes from java.util and java.lang:
var foo = Math.sqrt(4); // 2.0Number format conversion
Section titled “Number format conversion”Convert numbers to hex, octal, or binary using Integer.toString():
var b16 = Integer.toString(0x1A, 16); // "1a"var b10 = Integer.toString(0x1A, 10); // "26"var b8 = Integer.toString(0x1A, 8); // "32"var b2 = Integer.toString(0x1A, 2); // "11010"Negative numbers:
var i16 = Integer.toString(-255, 16); // "-ff"var i10 = Integer.toString(-255, 10); // "-255"var i8 = Integer.toString(-255, 8); // "-377"var i2 = Integer.toString(-255, 2); // "-11111111"Float and double hex strings:
var f0 = 7823764.8374;var f16 = Float.toHexString(f0); // "0x1.dd8654p22"
var dd0 = 99993219.156013e-002;var dd16 = Double.toHexString(dd0); // "0x1.e83f862142b5bp19"Long conversion:
var l16 = Long.toString(9223372036854775807, 16); // "7fffffffffffffff"var l10 = Long.toString(9223372036854775807, 10); // "9223372036854775807"var l8 = Long.toString(9223372036854775807, 8); // "777777777777777777777"var l2 = Long.toString(9223372036854775807, 2); // "111...111" (63 ones)Security constraints
Section titled “Security constraints”Creating new instances of Java classes is not allowed:
java.util.Collections.reverse(list); // allowed — static method calllist = new java.util.ArrayList(); // NOT allowed — constructor callJSON helper
Section titled “JSON helper”var metadataStr = JSON.stringify(metadata);var metadata = JSON.parse(metadataStr);Flow control
Section titled “Flow control”If / else if / else
Section titled “If / else if / else”if (temperature > 0) { return "Greater than zero!";} else if (temperature == -1) { return "Minus one!";} else { return "Something else!";}Ternary operator
Section titled “Ternary operator”temperature > 0 ? "Yes" : "No";Foreach
Section titled “Foreach”var numbers = [1, 2, 3];var sum = 0;foreach (n : numbers) { sum += n;}Strings are iterable character-by-character:
foreach (c : "ABCDEFGHIJKLMNOPQRSTUVWXYZ") { // process each character}For loop
Section titled “For loop”var sum = 0;for (var i = 0; i < 100; i++) { sum += i;}While and until
Section titled “While and until”while (isTrue()) { doSomething();}
until (isFalse()) { doSomething();}Do while / do until
Section titled “Do while / do until”do { x = something();} while (x != null);
do { x = something();} until (x == null);