diff options
| author | Alexander Shorin <kxepal@gmail.com> | 2011-12-25 21:40:27 +0400 |
|---|---|---|
| committer | Alexander Shorin <kxepal@gmail.com> | 2011-12-25 21:40:27 +0400 |
| commit | 17c634f6aa425988fcc2795daecac8a0307804e4 (patch) | |
| tree | f5ef8c9533ce41b411fc81588c16f2777080b5cf /jsonpatch.py | |
| parent | d20e3a6f2512df428aed7c029c52bd1e973a72dd (diff) | |
| download | python-json-patch-17c634f6aa425988fcc2795daecac8a0307804e4.tar.gz | |
Convert JsonPatch instance to JSON string in nicer way.
Diffstat (limited to 'jsonpatch.py')
| -rw-r--r-- | jsonpatch.py | 8 |
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.""" |
