Repository: tophat/syrupy

Issue:
JSONSnapshotExtension None is serialized as "None" instead of null
Is it intended behaviour that `None` is not translated to `null` with the JSONSnapshotExtension?

```python
@pytest.fixture
def snapshot_json(snapshot):
    return snapshot.use_extension(JSONSnapshotExtension)

def test_output(snapshot_json):
    assert {"x": None} == snapshot_json()
```

Actual Output:
```json
{
    "x": "None"
}
```

Expected Output:
```json
{
    "x": null
}
```

Digging into the code, it looks like there's no handling of None in _filter, and it eventually reaches `return repr(None)` line.

I can wrap the existing class with the following code:
```python
import pytest
from syrupy.extensions.json import JSONSnapshotExtension

@pytest.fixture
def snapshot_json(snapshot):
    class CustomJSONExtension(JSONSnapshotExtension):
        @classmethod
        def _filter(
            cls,
            data,
            **kwargs
        ):
            if data is None:
                return data
            else:
                return super()._filter(data, **kwargs)

    return snapshot.use_extension(CustomJSONExtension)

```

Was wondering if there's a different way to get this behaviour? 

Discussion:

Patch:
diff --git a/src/syrupy/extensions/json/__init__.py b/src/syrupy/extensions/json/__init__.py
index 0b9a954..d35a1ef 100644
--- a/src/syrupy/extensions/json/__init__.py
+++ b/src/syrupy/extensions/json/__init__.py
@@ -64,7 +64,7 @@ class JSONSnapshotExtension(SingleFileSnapshotExtension):
         elif matcher:
             data = matcher(data=data, path=path)
 
-        if isinstance(data, (int, float, str)):
+        if isinstance(data, (int, float, str)) or data is None:
             return data
 
         filtered_dct: Dict[Any, Any]


Test patch:
diff --git a/tests/syrupy/extensions/json/__snapshots__/test_json_filters/test_exclude_in_json_with_empty_values.json b/tests/syrupy/extensions/json/__snapshots__/test_json_filters/test_exclude_in_json_with_empty_values.json
index 2e8f310..71d5f1e 100644
--- a/tests/syrupy/extensions/json/__snapshots__/test_json_filters/test_exclude_in_json_with_empty_values.json
+++ b/tests/syrupy/extensions/json/__snapshots__/test_json_filters/test_exclude_in_json_with_empty_values.json
@@ -1,5 +1,5 @@
 {
   "empty_dict": {},
   "empty_list": [],
-  "none": "None"
+  "none": null
 }
diff --git a/tests/syrupy/extensions/json/__snapshots__/test_json_filters/test_serializer[content2].json b/tests/syrupy/extensions/json/__snapshots__/test_json_filters/test_serializer[content2].json
index f518b00..990521b 100644
--- a/tests/syrupy/extensions/json/__snapshots__/test_json_filters/test_serializer[content2].json
+++ b/tests/syrupy/extensions/json/__snapshots__/test_json_filters/test_serializer[content2].json
@@ -7,6 +7,6 @@
   "datetime": "2021-01-31T23:59:00.000000",
   "float": 4.2,
   "int": -1,
-  "null": "None",
+  "null": null,
   "str": "foo"
 }
diff --git a/tests/syrupy/extensions/json/__snapshots__/test_json_serializer/test_dict[actual2].json b/tests/syrupy/extensions/json/__snapshots__/test_json_serializer/test_dict[actual2].json
index 658b260..48e8cd1 100644
--- a/tests/syrupy/extensions/json/__snapshots__/test_json_serializer/test_dict[actual2].json
+++ b/tests/syrupy/extensions/json/__snapshots__/test_json_serializer/test_dict[actual2].json
@@ -1,4 +1,5 @@
 {
   "a": "Some ttext.",
+  "key": null,
   "multi\nline\nkey": "Some morre text."
 }
diff --git a/tests/syrupy/extensions/json/__snapshots__/test_json_serializer/test_empty_snapshot.json b/tests/syrupy/extensions/json/__snapshots__/test_json_serializer/test_empty_snapshot.json
index 68cab94..19765bd 100644
--- a/tests/syrupy/extensions/json/__snapshots__/test_json_serializer/test_empty_snapshot.json
+++ b/tests/syrupy/extensions/json/__snapshots__/test_json_serializer/test_empty_snapshot.json
@@ -1,1 +1,1 @@
-"None"
+null
diff --git a/tests/syrupy/extensions/json/test_json_serializer.py b/tests/syrupy/extensions/json/test_json_serializer.py
index 7a6a2c1..9c1e359 100644
--- a/tests/syrupy/extensions/json/test_json_serializer.py
+++ b/tests/syrupy/extensions/json/test_json_serializer.py
@@ -124,6 +124,7 @@ def test_set(snapshot_json, actual):
             "multi\nline\nkey": "Some morre text.",
             frozenset({"1", "2"}): ["1", 2],
             ExampleTuple(a=1, b=2, c=3, d=4): {"e": False},
+            "key": None,
         },
         {},
         {"key": ["line1\nline2"]},