Undefined method `each' for nil:NilClass

Hi,
We are trying to flatten a json array with the following ruby code in Logstash

ruby {
  init => '@ignore = [ "@metadata", "@version" , "beat", "type", "tags"]'
  code => '
    event.get("[EventData]").each { | k, v| event.set(k, v) }
    event.remove("EventData")
    event.remove("user")
    s = ""
    event.to_hash.each { |k, v|
      unless @ignore.include?(k)
        s = s + "#{k}=\"#{v}\" "
      end
      event.set("rawMessage", s.chomp(","))
    }
  '
}

And we get the following error:
Ruby exception occurred: undefined method `each' for nil:NilClass
Someone can help us ?

That would very much suggest that there is no EventData field on the message.