summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorDavid Vo <auscompgeek@users.noreply.github.com>2020-08-07 22:02:55 +1000
committerGitHub <noreply@github.com>2020-08-07 08:02:55 -0400
commit4dd27e6d1125df83a754b5e0c2c14aaafc0ce837 (patch)
treedb0e46cd9c3f2f94cedb200d5599a4b4d61651de /synapse/util
parentRevert #7736 (#8039) (diff)
downloadsynapse-4dd27e6d1125df83a754b5e0c2c14aaafc0ce837.tar.xz
Reduce unnecessary whitespace in JSON. (#7372)
Diffstat (limited to '')
-rw-r--r--synapse/util/__init__.py4
-rw-r--r--synapse/util/frozenutils.py7
2 files changed, 9 insertions, 2 deletions
diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py
index c63256d3bd..b3f76428b6 100644
--- a/synapse/util/__init__.py
+++ b/synapse/util/__init__.py
@@ -17,6 +17,7 @@ import logging
 import re
 
 import attr
+from canonicaljson import json
 
 from twisted.internet import defer, task
 
@@ -24,6 +25,9 @@ from synapse.logging import context
 
 logger = logging.getLogger(__name__)
 
+# Create a custom encoder to reduce the whitespace produced by JSON encoding.
+json_encoder = json.JSONEncoder(separators=(",", ":"))
+
 
 def unwrapFirstError(failure):
     # defer.gatherResults and DeferredLists wrap failures.
diff --git a/synapse/util/frozenutils.py b/synapse/util/frozenutils.py
index eab78dd256..0e445e01d7 100644
--- a/synapse/util/frozenutils.py
+++ b/synapse/util/frozenutils.py
@@ -63,5 +63,8 @@ def _handle_frozendict(obj):
     )
 
 
-# A JSONEncoder which is capable of encoding frozendicts without barfing
-frozendict_json_encoder = json.JSONEncoder(default=_handle_frozendict)
+# A JSONEncoder which is capable of encoding frozendicts without barfing.
+# Additionally reduce the whitespace produced by JSON encoding.
+frozendict_json_encoder = json.JSONEncoder(
+    default=_handle_frozendict, separators=(",", ":"),
+)