ParseInt

Learn about the ParseInt OTTL converter function.

The ParseInt converter converts a string representation of a number into an integer value.

Syntax: ParseInt(target, base)

  • target: the string to convert to an integer
  • base: the numeric base (radix) for parsing. Common values are 10 (decimal), 16 (hexadecimal), 8 (octal), or 2 (binary)

The returned type is int64.

Input

{
	"_type": "log",
	"body": {
		"int_string": "12345",
		"run": 23
	},
	"resource": {...},
	"timestamp": 1727750400000
}

Statement

set(body["parsed_int"], ParseInt(body["int_string"], 10))

Output

{
	"_type": "log",
	"body": {
		"int_string": "12345",
		"parsed_int": 12345,
		"run": 23
	},
	"resource": {...},
	"timestamp": 1727750400000
}

The string “12345” was successfully converted to the integer value 12345 using base 10 (decimal).