Hello, I have an event which is nested like this:
{
"test1": null,
"test2": null,
"test3": {
"test31": null,
"test32": null,
},
"test4":{
"test5": [
{
"test6": null,
"test7": null
} ]
}
etc
and I would like to find null values in it recursively and rename the fields that have those null values. So far I have done something like this in logstash config, it only handles hashes (haven't found how to handle arrays this way)
def first_meth(e)
hash_event = e.to_hash
new_meth(hash_event, e)
end
def new_meth(hash, ev)
hash.each do |key,value|
if value == nil
ev.set("[#{key}_null]", value)
ev.remove("[#{key}]")
end
if value.kind_of?(Hash)
f = ev.get("[#{key}]")
new_meth(f, ev)
end
end
end
somewhere else in the ruby code I call
first_meth(event)
the thing is it puts everything in root level. I don't want to change the structure. How could I do this?
{
"test1_null": null,
"test2_null": null,
"test3": {
"test31_null": null,
"test32_null": null,
},
"test4":{
"test5": [
{
"test6_null": null,
"test7_null": null
} ]
}
Thank you