String

Learn about the String OTTL converter function.

The String converter converts a non-string field to a string.

Syntax: String(value)

  • value: the bracket notation location of the field to convert

Input

{
	"_type": "log",
	"timestamp": 1734586243207,
	"body": "{\"host\": \"172.17.15.39\", \"user-identifier\": \"68b148de-7ce3-423c-b72d-64a4f21ecfc0\", \"time_local\": \"2024-12-15T22:40:53.723160Z\", \"method\": \"POST\", \"request\": \"/styles/main.css\", \"protocol\": \"HTTP/2\", \"status\": 403, \"bytes_sent\": 1043}",
	"resource": {...},
	"attributes": {
		"parsed_body": {
			"bytes_sent": 1043,
			"host": "172.17.15.39",
			"method": "POST",
			"protocol": "HTTP/2",
			"request": "/styles/main.css",
			"status": 403,
			"time_local": "2024-12-15T22:40:53.723160Z",
			"user-identifier": "68b148de-7ce3-423c-b72d-64a4f21ecfc0"
		}
	}
}

Statement

set(attributes["parsed_body"]["status"], String(attributes["parsed_body"]["status"]))

Output

{
	"_type": "log",
	"timestamp": 1734586277255,
	"body": "{\"host\": \"172.17.15.39\", \"user-identifier\": \"68b148de-7ce3-423c-b72d-64a4f21ecfc0\", \"time_local\": \"2024-12-15T22:40:53.723160Z\", \"method\": \"POST\", \"request\": \"/styles/main.css\", \"protocol\": \"HTTP/2\", \"status\": 403, \"bytes_sent\": 1043}",
	"resource": {...},
	"attributes": {
		"parsed_body": {
			"bytes_sent": 1043,
			"host": "172.17.15.39",
			"method": "POST",
			"protocol": "HTTP/2",
			"request": "/styles/main.css",
			"status": "403",
			"time_local": "2024-12-15T22:40:53.723160Z",
			"user-identifier": "68b148de-7ce3-423c-b72d-64a4f21ecfc0"
		}
	}
}

The numeric value 403 was converted to its string representation "403".