1
我试图发送json字符串到logstash,然后kafka,但由于我的json文件中的双引号溢出,我一直遇到json解析失败。Logstash JSON输入与转义双引号
我试过一堆不同的替换组合,但没有一个可以工作。我不知道如果
- 在配置的输入侧已经出现的错误,所以它不是继续滤光片部分
- 我只是没有正确更换琴弦
我得到一个JSON作为:
{"message": "This is a \"string with quote"}
我logstash的conf是:
input {
tcp {
codec => json { charset => "UTF-8" }
port => 10000
}
}
filter {
json {
source => "message"
}
mutate {
remove_field => ["@version", "@timestamp", "host", "port"]
gsub => [
# replace all backslashes + double quote with space
'body', '\\"', ' '
]
}
}
output {
kafka {
bootstrap_servers => "localhost:9092"
codec => json {charset => "UTF-8"}
topic_id => 'logstash_logs'
}
file {
path => "/usr/share/logstash/test.log"
codec => rubydebug
}
}
我rubydebug日志:
{
"message" => "{\"message\": \"This is a \"string with quote\"}",
"tags" => [
[0] "_jsonparsefailure"
]
}
什么是完整的来源讯息? –
我收到的实际消息是来自优质新闻源的新闻文章。摘录如下:{“an”:“AFNWS00020150624eb6o0006h”,“body”:“该展览旨在展示可再生能源的潜力,... \ n \ n”我们正在让农村地区她说,“我们一直在优先考虑太阳能电池板,为学校和医院等社会基础设施提供电力”。} – Merelda