Bool

Convert strings and numbers to boolean values using the Bool OTTL converter function.

Overview

The Bool converter converts a value to a boolean. It accepts strings ("true", "false") and numbers (1, 0).

Syntax

Bool(value)

  • value: the value to convert to boolean

Examples

Input

{
	"_type": "log",
	"body": {
		"enabled": "true",
		"count": 1,
		"disabled": "false",
		"zero": 0
	},
	"resource": {...},
	"attributes": {}
}

Statement

set(attributes["from_true_str"], Bool(body["enabled"]))
set(attributes["from_1"], Bool(body["count"]))
set(attributes["from_false_str"], Bool(body["disabled"]))
set(attributes["from_0"], Bool(body["zero"]))

Output

{
	"_type": "log",
	"body": {
		"enabled": "true",
		"count": 1,
		"disabled": "false",
		"zero": 0
	},
	"resource": {...},
	"attributes": {
		"from_true_str": true,
		"from_1": true,
		"from_false_str": false,
		"from_0": false
	}
}

The string "true" and number 1 both converted to true. The string "false" and number 0 both converted to false.