Skip to content

Instantly share code, notes, and snippets.

@toretore
Forked from graingert/flatten.rb
Last active October 14, 2015 17:12
Show Gist options
  • Save toretore/a63fcf3e17d47723d87f to your computer and use it in GitHub Desktop.
Save toretore/a63fcf3e17d47723d87f to your computer and use it in GitHub Desktop.
module Fluent
class TextParser
class StringifiedValuesJSONParser < JSONParser
Plugin.register_parser("stringified_values_json", self)
def parse(text)
time, record = super(text)
# replace all Hash (like a dict) values with stringified JSON
record = record.inject({}) { | new_hash, (key, value) |
if value.is_a?(Hash)
new_hash[key] = JSON.dump(value)
else
new_hash[key] = v
end
new_hash
}
yield time, record
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment