Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

How to delete a key and keep it's value, the value is an hash #245

Open
sanmingzi opened this issue Dec 5, 2016 · 2 comments
Open

How to delete a key and keep it's value, the value is an hash #245

sanmingzi opened this issue Dec 5, 2016 · 2 comments

Comments

@sanmingzi
Copy link

input: "params": {"key1": "value1"}
output: {"key1": "value1"}
This is my use case. Thank you.

@sanmingzi
Copy link
Author

sanmingzi commented Dec 5, 2016

def filter(tag, time, record)
  if record['params']
    value = record['params']
    record.merge!(value)
    record.delete('params')
  end
end

I write a filter plugin, some code like this. It can work. But I think the method is complex.
Any simple solution?

@okkez
Copy link
Contributor

okkez commented Sep 27, 2018

def filter(tag, time, record)
  if params.key?("params")
    new_record = record["params"]
    new_record
  else
    record
  end
end

The filter method must return the new modified record or original record.

BTW, record_transformer Filter Plugin is suitable for the purpose.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants