Hello,
I am trying to parse a nested json which have dynamic keys.
I am just able for now to extract data from the first json object, i dont understand what is going wrong in my ruby filter.
Also in the output the whole input json is shown, i just want to have the result of the ruby filter parsing.
Logstash version : 6.2.4
Thanks in advance for any help.
input {
file {
path => ["/tmp/test.json"]
start_position => "beginning"
codec => "json"
sincedb_path => "/dev/null"
}
}
filter {
mutate {
remove_field => [ "@version", "@timestamp", "host", "path", "version" ]
}
ruby {
code => "
event.to_hash.clone.each_value{|v|
if v.is_a? Hash
v.each_pair{|k,v|
event.set(k,v)
}
end
}
"
}
}
output {
file {
path => "/tmp/test-result.json"
write_behavior => "overwrite"
}
}
input file /tmp/test.json ( with json pretty format ) :
{
"10": {
"latitude": "483751298",
"longitude": "193654098"
},
"11": {
"latitude": "583751298",
"longitude": "293654098"
},
"12": {
"latitude": "583751298",
"longitude": "393654098"
},
"version": "1"
}
output file /tmp/test-result.json ( with json pretty format ) :
{
"10": {
"latitude": "483751298",
"longitude": "193654098"
},
"11": {
"latitude": "583751298",
"longitude": "293654098"
},
"12": {
"latitude": "583751298",
"longitude": "393654098"
},
"latitude": "483751298",
"longitude": "193654098"
}
Regards,
Nicolas