Pretty print JSON text widget for admin?

“Cleaving” from this thread: Add JSON editor widget to Django Admin for JSON fields, inspired by @josdejong/jsoneditor · Issue #84 · django/new-features · GitHub

Problem: The json widget just dumps the json value as a single line and it’s pretty annoying to work with.

Solution? The requested feature was to supply a js based json editor. I think we should steer clear of more js addons… But what we can do is at least pretty print the JSON to make it easier to edit.

I think though, admin should at least pretty print json to make it easier to edit. Dealing with all that JSON in a single line is a headache.

Yep, last time I had an admin workflow on a JSON field, I provided a custom encoder that supplied the indent arg; we should (likely*) just fix DjangoJSONEncoder.__init__() to use a default indent value. Should we cleave this off into a separate issue?

(*) caveat: first impression, haven’t hunted yet for backwards-compat implications.

@jacobtylerwalls I don’t think we can modify DjangoJSONEncoder like that because it’s used with JsonResponse

4 Likes

Having the widget default the indent argument to 2 seems good and desirable to me, as long as it doesn’t affect the stored value.

2 Likes