Format default user preferences (and other) JSON when populating the config editor #9037

Closed
opened 2025-12-29 20:44:35 +01:00 by adam · 2 comments
Owner

Originally created by @markkuleinio on GitHub (Jan 4, 2024).

Originally assigned to: @markkuleinio on GitHub.

NetBox version

v3.7.0

Feature type

Change to existing functionality

Proposed functionality

When editing Default user preferences in Current Config - Edit, the JSON is shown just dumped, like this (very short example):

{"tables": {"ASNTable": {"columns": ["asn", "tags"]}, "RackTable": {"columns": ["name", "site", "get_utilization", "get_power_utilization"]}}}

I propose that the JSON data would be formatted using the same formatter as in the Current Config screen (before editing, showing JSON nicely structured and indented) before showing it in the edit box, instead of just dumping the compressed JSON data there.

If there are other similar JSON-based configuration items, this same principle can probably be used in them all.

Use case

When fine-tuning the typically very long JSON data in the config editor it is hard to locate and understand particular keys and values in the unformatted JSON dump. Formatting the JSON data nicely will help editing the data and preventing errors when modifying and saving the configuration.

Even if the editor shows the data structured and indented, it is nevertheless saved in the optimal compressed format, so there is no loss of efficiency in the database.

Database changes

None

External dependencies

None (json module from Python standard library can be used unless some other method is already preferred in NetBox)

Originally created by @markkuleinio on GitHub (Jan 4, 2024). Originally assigned to: @markkuleinio on GitHub. ### NetBox version v3.7.0 ### Feature type Change to existing functionality ### Proposed functionality When editing **Default user preferences** in Current Config - Edit, the JSON is shown just dumped, like this (very short example): > {"tables": {"ASNTable": {"columns": ["asn", "tags"]}, "RackTable": {"columns": ["name", "site", "get_utilization", "get_power_utilization"]}}} I propose that the JSON data would be formatted using the same formatter as in the Current Config screen (before editing, showing JSON nicely structured and indented) before showing it in the edit box, instead of just dumping the compressed JSON data there. If there are other similar JSON-based configuration items, this same principle can probably be used in them all. ### Use case When fine-tuning the typically very long JSON data in the config editor it is hard to locate and understand particular keys and values in the unformatted JSON dump. Formatting the JSON data nicely will help editing the data and preventing errors when modifying and saving the configuration. Even if the editor shows the data structured and indented, it is nevertheless saved in the optimal compressed format, so there is no loss of efficiency in the database. ### Database changes None ### External dependencies None (`json` module from Python standard library can be used unless some other method is already preferred in NetBox)
adam added the status: acceptedtype: feature labels 2025-12-29 20:44:35 +01:00
adam closed this issue 2025-12-29 20:44:35 +01:00
Author
Owner

@markkuleinio commented on GitHub (Jan 20, 2024):

I have tested code for this, so I'm willing to submit a PR if this FR is accepted.

@markkuleinio commented on GitHub (Jan 20, 2024): I have tested code for this, so I'm willing to submit a PR if this FR is accepted.
Author
Owner

@jeffgdotorg commented on GitHub (Apr 3, 2024):

Thanks for opening this FR, and for your patience. Please get that PR going and we'll see if there are any issues with the approach you chose.

For the benefit of future GitHub archaeologists, and to placate my inner pedant, I'm going to describe as "minified" the JSON formatting that you describe as "compressed".

@jeffgdotorg commented on GitHub (Apr 3, 2024): Thanks for opening this FR, and for your patience. Please get that PR going and we'll see if there are any issues with the approach you chose. For the benefit of future GitHub archaeologists, and to placate my inner pedant, I'm going to describe as "minified" the JSON formatting that you describe as "compressed".
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9037