add shortcut jsonpatch.apply_patch(doc, patch)

This commit is contained in:
Stefan Kögl
2011-06-20 16:04:04 +02:00
parent df999c9b43
commit bc94e06069

View File

@@ -47,6 +47,18 @@ class JsonPatchException(Exception):
pass
def apply_patch(doc, patch):
"""
>>> obj = { 'baz': 'qux', 'foo': 'bar' }
>>> patch = [ { 'remove': '/baz' } ]
>>> apply_patch(obj, patch)
{'foo': 'bar'}
"""
p = JsonPatch(patch)
return p.apply(doc)
class JsonPatch(object):
""" A JSON Patch is a list of Patch Operations """