我想将字段转换为json列表,sg如下: “人”:{ “名”: “XX”, “住址”: “124” }
到
“person”:[{“name”:“XX”, “地址”:“124”}]
感谢您的帮助。
答案 0 :(得分:1)
这里有一点红宝石魔法:
input {
stdin{}
}
filter {
ruby {
code => "
require 'json'
event['res'] = [JSON.parse(event['message'])['person']]
"
}
}
output {
stdout { codec => rubydebug }
}
这将简单地解析包含Json文档的message
字段,然后提取person
对象并将其添加到字段中。
测试看起来如此:
artur@pandaadb:~/dev/logstash$ ./logstash-2.3.2/bin/logstash -f conf_json_list/
Settings: Default pipeline workers: 8
Pipeline main started
{ "person": { "name":"XX", "adress":"124" }}
{
"message" => "{ \"person\": { \"name\":\"XX\", \"adress\":\"124\" }}",
"@version" => "1",
"@timestamp" => "2017-03-15T11:34:37.424Z",
"host" => "pandaadb",
"res" => [
[0] {
"name" => "XX",
"adress" => "124"
}
]
}
如您所见,您的哈希现在位于索引0的列表中。
希望有所帮助,
Artur