summaryrefslogtreecommitdiff
path: root/jsonpatch.py
diff options
context:
space:
mode:
authorAlexander Shorin <kxepal@gmail.com>2011-12-25 21:40:27 +0400
committerAlexander Shorin <kxepal@gmail.com>2011-12-25 21:40:27 +0400
commit17c634f6aa425988fcc2795daecac8a0307804e4 (patch)
treef5ef8c9533ce41b411fc81588c16f2777080b5cf /jsonpatch.py
parentd20e3a6f2512df428aed7c029c52bd1e973a72dd (diff)
downloadpython-json-patch-17c634f6aa425988fcc2795daecac8a0307804e4.tar.gz
Convert JsonPatch instance to JSON string in nicer way.
Diffstat (limited to 'jsonpatch.py')
-rw-r--r--jsonpatch.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/jsonpatch.py b/jsonpatch.py
index a28af75..5e538dd 100644
--- a/jsonpatch.py
+++ b/jsonpatch.py
@@ -146,12 +146,20 @@ class JsonPatch(object):
'test': TestOperation
}
+ def __str__(self):
+ """str(self) -> self.to_string()"""
+ return self.to_string()
+
@classmethod
def from_string(cls, patch_str):
"""Creates JsonPatch instance from string source."""
patch = json.loads(patch_str)
return cls(patch)
+ def to_string(self):
+ """Returns patch set as JSON string."""
+ return json.dumps(self.patch)
+
def apply(self, obj):
"""Applies the patch to given object."""