{\n"protocol":"HTTP/1.1",\n"remote_addr":"127.0.0.1"}
I have the follwing json message and I'm looking to use the mutate gsub filter to do two things:
1 - remove the \n
2 - remove the \ (backslashes)
Ideally i would like to get the following format:
{"protocol":"HTTP/1.1","remote_addr":"127.0.0.1"}
It seems like the mutate gsub is not working as expected on serialized json... Here is a snippet of my logstash.conf
json{
source => "message"
target => "parsedJson"
remove_field=>["message"]
}
if [parsedJson][logger_name] == "com.test" {
mutate{
gsub => ["[parsedJson][message]", "[\n]", ""]
gsub => ["[parsedJson][message]", "[\\]", ""]
}
json {
source => "message"
target => "newmessage"
}
}
}
Here is the event output
{
"@version" => "1",
"path" => "/test/api-logstash.log",
"parsedJson" => {
"logger_name" => "com.test",
"level" => "INFO",
"@version" => 1,
"thread_name" => "dw-29",
"level_value" => 20000,
"@timestamp" => "2019-04-15T18:34:49.679-04:00",
"message" => "{"protocol":"HTTP/1.1","remote_addr":"127.0.0.1"}"
},
"host" => "myserver",
"@timestamp" => 2019-04-15T22:34:50.465Z
}
As you can see the newline is removed but the backslashes are still there. Any idea on how to achieve this?