You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/serialization.rst
+33-1Lines changed: 33 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -34,15 +34,47 @@ Example:
34
34
To Json
35
35
-------
36
36
37
+
Dump json of the text view.
38
+
37
39
In order to do safe json serialization, use the to_json() method.
38
40
39
-
Example:
41
+
**Parameters**
42
+
43
+
default_mapping : dictionary(optional), a dictionary of mapping of different types to json types.
44
+
45
+
by default DeepDiff converts certain data types. For example Decimals into floats so they can be exported into json.
46
+
If you have a certain object type that the json serializer can not serialize it, please pass the appropriate type
47
+
conversion through this dictionary.
48
+
49
+
kwargs: Any other kwargs you pass will be passed on to Python's json.dumps()
50
+
51
+
52
+
Example 1 Serialize custom objects:
53
+
>>> classA:
54
+
... pass
55
+
...
56
+
>>> classB:
57
+
... pass
58
+
...
59
+
>>> t1 = A()
60
+
>>> t2 = B()
61
+
>>> ddiff = DeepDiff(t1, t2)
62
+
>>> ddiff.to_json()
63
+
TypeError: We do not know how to convert <__main__.A object at 0x10648> of type <class '__main__.A'> for json serialization. Please pass the default_mapping parameter with proper mapping of the object to a basic python type.
0 commit comments