ParseJSON

Learn about the ParseJSON OTTL converter function.

The ParseJSON converter parses a JSON string into an object.

Syntax: ParseJSON(value)

  • value: the bracket notation location of the JSON string to parse

Input

{
	"_type": "log",
	"timestamp": 1734494063084,
	"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": {...}
}

Statement

set(attributes["decoded_body"], Decode(body, "utf-8"))
set(attributes["parsed_body"], ParseJSON(attributes["decoded_body"]))

See Working with the body for more information.

Output

{
	"_type": "log",
	"timestamp": 1734494114238,
	"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": {
		"decoded_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}",
		"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 JSON string was parsed into the parsed_body attribute.