Last active
August 29, 2015 14:20
-
-
Save samv/666c0ca386dfde7db1d7 to your computer and use it in GitHub Desktop.
Remove 'unknown' json fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JsonRecord(unknown_json_keys={'foo': 'bar'}) | |
JsonRecord() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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