Skip to content

feat: support pretty printing in tojson filter (#681)#769

Open
SHYXIN wants to merge 3 commits into
jowilf:mainfrom
SHYXIN:fix/jsonfield-pretty-print
Open

feat: support pretty printing in tojson filter (#681)#769
SHYXIN wants to merge 3 commits into
jowilf:mainfrom
SHYXIN:fix/jsonfield-pretty-print

Conversation

@SHYXIN

@SHYXIN SHYXIN commented May 17, 2026

Copy link
Copy Markdown
Contributor

Summary

The custom tojson filter now accepts an optional indent parameter, enabling pretty printed JSON output in templates. Default behavior is unchanged.

Changes

  • starlette_admin/base.py:255 — Added indent=None parameter to the tojson filter lambda

Usage

{{ data|tojson }}           # compact (default, backward compatible)
{{ data|tojson(indent=2) }} # pretty printed with 2-space indent

Users can override the JSONField display template to use pretty printing:

JSONField("json_data", display_template="admin/json_pretty_print.html")

With a custom template:

<div class="field-json">{{ data|tojson(indent=2) }}</div>

Testing

  • All 16 tests pass (test_views.py + test_converters.py)

Additional

Includes chore commit to fix pyproject.toml pytest config conflict.

SHYXIN and others added 3 commits May 17, 2026 16:55
The custom tojson filter now accepts an optional indent parameter,
enabling pretty printed JSON output in templates. Default behavior
is unchanged (no indent).

Usage in templates:
  {{ data|tojson }}           # compact (default)
  {{ data|tojson(indent=2) }} # pretty printed
@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (0f684fe) to head (9532f25).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #769   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           86        86           
  Lines         6848      6848           
=========================================
  Hits          6848      6848           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant