Repository: xlwings/jsondiff

Issue:
No difference label if one of JSON is empty
Hi,

I did some tests with the library and I have a case scenario where one of the compared JSON is empty: { }. I am using syntax='explicit' and the diff returns me exactly the JSON that is not the one empty. My problem is that I would like it to return me something like:

```js
{
  insert: ...
}
```

The "insert" tag is quite important during my parsing.

Discussion:

Patch:
diff --git a/jsondiff/__init__.py b/jsondiff/__init__.py
index e2920c4..a3fdcc2 100644
--- a/jsondiff/__init__.py
+++ b/jsondiff/__init__.py
@@ -84,7 +84,7 @@ class CompactJsonDiffSyntax(object):
     def emit_list_diff(self, a, b, s, inserted, changed, deleted):
         if s == 0.0:
             return {replace: b} if isinstance(b, dict) else b
-        elif s == 1.0:
+        elif s == 1.0 and not (inserted or changed or deleted):
             return {}
         else:
             d = changed
@@ -97,7 +97,7 @@ class CompactJsonDiffSyntax(object):
     def emit_dict_diff(self, a, b, s, added, changed, removed):
         if s == 0.0:
             return {replace: b} if isinstance(b, dict) else b
-        elif s == 1.0:
+        elif s == 1.0 and not (added or changed or removed):
             return {}
         else:
             changed.update(added)
@@ -171,9 +171,9 @@ class ExplicitJsonDiffSyntax(object):
             return d
 
     def emit_list_diff(self, a, b, s, inserted, changed, deleted):
-        if s == 0.0:
+        if s == 0.0 and not (inserted or changed or deleted):
             return b
-        elif s == 1.0:
+        elif s == 1.0 and not (inserted or changed or deleted):
             return {}
         else:
             d = changed
@@ -184,9 +184,9 @@ class ExplicitJsonDiffSyntax(object):
             return d
 
     def emit_dict_diff(self, a, b, s, added, changed, removed):
-        if s == 0.0:
+        if s == 0.0 and not (added or changed or removed):
             return b
-        elif s == 1.0:
+        elif s == 1.0 and not (added or changed or removed):
             return {}
         else:
             d = {}
@@ -218,9 +218,9 @@ class SymmetricJsonDiffSyntax(object):
             return d
 
     def emit_list_diff(self, a, b, s, inserted, changed, deleted):
-        if s == 0.0:
+        if s == 0.0 and not (inserted or changed or deleted):
             return [a, b]
-        elif s == 1.0:
+        elif s == 1.0 and not (inserted or changed or deleted):
             return {}
         else:
             d = changed
@@ -231,9 +231,9 @@ class SymmetricJsonDiffSyntax(object):
             return d
 
     def emit_dict_diff(self, a, b, s, added, changed, removed):
-        if s == 0.0:
+        if s == 0.0 and not (added or changed or removed):
             return [a, b]
-        elif s == 1.0:
+        elif s == 1.0 and not (added or changed or removed):
             return {}
         else:
             d = changed


Test patch:
diff --git a/tests/test_jsondiff.py b/tests/test_jsondiff.py
index 8328ee9..2cbbc66 100644
--- a/tests/test_jsondiff.py
+++ b/tests/test_jsondiff.py
@@ -1,5 +1,6 @@
 import sys
 import unittest
+import pytest
 
 from jsondiff import diff, replace, add, discard, insert, delete, update, JsonDiffer
 
@@ -134,3 +135,30 @@ class JsonDiffTests(unittest.TestCase):
             self.fail('cannot diff long arrays')
         finally:
             sys.setrecursionlimit(r)
+
+
+@pytest.mark.parametrize(
+    ("a", "b", "syntax", "expected"),
+    [
+        pytest.param([], [{"a": True}], "explicit", {insert: [(0, {"a": True})]},
+                     id="issue59_"),
+        pytest.param([{"a": True}], [], "explicit", {delete: [0]},
+                     id="issue59_"),
+        pytest.param([], [{"a": True}], "compact", [{"a": True}],
+                     id="issue59_"),
+        pytest.param([{"a": True}], [], "compact", [],
+                     id="issue59_"),
+        pytest.param([], [{"a": True}], "symmetric", {insert: [(0, {"a": True})]},
+                     id="issue59_"),
+        pytest.param([{"a": True}], [], "symmetric", {delete: [(0, {"a": True})]},
+                     id="issue59_"),
+        pytest.param({1: 2}, {5: 3}, "symmetric", {delete: {1: 2}, insert: {5: 3}},
+                     id="issue36_"),
+        pytest.param({1: 2}, {5: 3}, "compact", {replace: {5: 3}},
+                     id="issue36_"),
+    ],
+)
+class TestSpecificIssue:
+    def test_issue(self,  a, b, syntax, expected):
+        actual = diff(a, b, syntax=syntax)
+        assert actual == expected