From 3f91f2ac27ab6c6b7c030775df44ac15a0338de6 Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Mon, 15 Feb 2021 21:08:20 +0100
Subject: [PATCH] Implement JSON pretty-printing

---
 dj_iconify/views.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/dj_iconify/views.py b/dj_iconify/views.py
index afd4d28..68501be 100644
--- a/dj_iconify/views.py
+++ b/dj_iconify/views.py
@@ -40,6 +40,12 @@ class IconifyJSONView(View):
         if format_ == "js":
             callback = request.GET.get("callback", "SimpleSVG._loaderCallback")
 
+        # Client can request pretty-printing of JSON
+        if request.GET.get("pretty", "0").lower() in ("1", "true"):
+            indent = 2
+        else:
+            indent = None
+
         # Load icon set through Iconify types
         collection_file = os.path.join(JSON_ROOT, "json", f"{collection}.json")
         try:
@@ -49,7 +55,7 @@ class IconifyJSONView(View):
             raise Http404(f"Icon collection {collection} not found") from exc
 
         # Get result JSON and form response
-        res = json.dumps(icon_set.as_dict())
+        res = json.dumps(icon_set.as_dict(), indent=indent, sort_keys=True)
         if format_ == "js":
             res = f"{callback}({res})"
             return HttpResponse(res, content_type="application/javascript")
-- 
GitLab