Strip leading and trailing brackets from prettified JSON

This commit is contained in:
Mark Veidemanis 2023-02-09 19:08:27 +00:00
parent 6a01aea5e1
commit d8005fa15d
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 7 additions and 1 deletions

View File

@ -6,4 +6,10 @@ register = template.Library()
@register.filter
def pretty(data):
return orjson.dumps(data, option=orjson.OPT_INDENT_2).decode("utf-8")
prettified = orjson.dumps(data, option=orjson.OPT_INDENT_2).decode("utf-8")
if prettified.startswith("{"):
prettified = prettified[1:]
if prettified.endswith("}"):
prettified = prettified[:-1]
return prettified