diff --git a/dj_iconify/views.py b/dj_iconify/views.py index afd4d286ffc74dd73267c4b82082f3ceb5487784..68501be31e0bba79c075257638d0b435576cbcec 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")