Skip to content

Commit 9b4fd51

Browse files
committed
Pass json.dumps parameters in DeepDiff.to_json #226
1 parent 1e1df14 commit 9b4fd51

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: [seperman]
2+
ko_fi: seperman

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DeepDiff Change log
22

3-
- v5-2-3: Retaining the order of multiple dictionary items added via Delta. Fixed the typo with yml files in deep cli. Fixing Grep RecursionError where using non UTF-8 character.
3+
- v5-2-3: Retaining the order of multiple dictionary items added via Delta. Fixed the typo with yml files in deep cli. Fixing Grep RecursionError where using non UTF-8 character. Allowing kwargs to be passed to to_json method.
44
- v5-2-2: Fixed Delta serialization when None type is present.
55
- v5-2-0: Removed Murmur3 as the preferred hashing method. Using SHA256 by default now. Added commandline for deepdiff. Added group_by. Added math_epsilon. Improved ignoring of NoneType.
66
- v5-0-2: Bug Fix NoneType in ignore type groups https://github.com/seperman/deepdiff/issues/207

deepdiff/serialization.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def from_json_pickle(cls, value):
116116
else:
117117
logger.error('jsonpickle library needs to be installed in order to run from_json_pickle') # pragma: no cover. Json pickle is getting deprecated.
118118

119-
def to_json(self, default_mapping=None):
119+
def to_json(self, default_mapping=None, **kwargs):
120120
"""
121121
Dump json of the text view.
122122
**Parameters**
@@ -127,6 +127,8 @@ def to_json(self, default_mapping=None):
127127
If you have a certain object type that the json serializer can not serialize it, please pass the appropriate type
128128
conversion through this dictionary.
129129
130+
kwargs: Any other kwargs you pass will be passed on to Python's json.dumps()
131+
130132
**Example**
131133
132134
Serialize custom objects
@@ -147,7 +149,7 @@ def to_json(self, default_mapping=None):
147149
'{"type_changes": {"root": {"old_type": "A", "new_type": "B", "old_value": "obj A", "new_value": "obj B"}}}'
148150
"""
149151
dic = self.to_dict(view_override=TEXT_VIEW)
150-
return json.dumps(dic, default=json_convertor_default(default_mapping=default_mapping))
152+
return json.dumps(dic, default=json_convertor_default(default_mapping=default_mapping), **kwargs)
151153

152154
def to_dict(self, view_override=None):
153155
"""

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Changelog
55

66
DeepDiff Changelog
77

8-
- v5-2-3: Retaining the order of multiple dictionary items added via Delta. Fixed the typo with yml files in deep cli. Fixing Grep RecursionError where using non UTF-8 character.
8+
- v5-2-3: Retaining the order of multiple dictionary items added via Delta. Fixed the typo with yml files in deep cli. Fixing Grep RecursionError where using non UTF-8 character. Allowing kwargs to be passed to to_json method.
99
- v5-2-2: Fixed Delta serialization when None type is present.
1010
- v5-2-0: Removed Murmur3 as the preferred hashing method. Using SHA256 by default now. Added commandline for deepdiff. Added group_by. Added math_epsilon. Improved ignoring of NoneType.
1111
- v5-0-2: Bug Fix NoneType in ignore type groups https://github.com/seperman/deepdiff/issues/207

0 commit comments

Comments
 (0)