Skip to content

Instantly share code, notes, and snippets.

@samv
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samv/666c0ca386dfde7db1d7 to your computer and use it in GitHub Desktop.
Save samv/666c0ca386dfde7db1d7 to your computer and use it in GitHub Desktop.
Remove 'unknown' json fields
JsonRecord(unknown_json_keys={'foo': 'bar'})
JsonRecord()
from normalize import JsonRecord
from normalize.visitor import VisitorPattern
class RemoveUnknownKeys(VisitorPattern):
@classmethod
def unpack(cls, value, t, v):
if hasattr(value, "unknown_json_keys"):
del value.unknown_json_keys
return super(RemoveUnknownKeys, cls).unpack(value, t, v)
@classmethod
def apply(cls, *a):
return None
@classmethod
def reduce(cls, *a):
return None
jr = JsonRecord({"foo": "bar"})
print repr(jr)
RemoveUnknownKeys.visit(jr)
print repr(jr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment