Add JSON schema validation for JSON custom fields #10954

Open
opened 2025-12-29 21:38:22 +01:00 by adam · 1 comment
Owner

Originally created by @sleepinggenius2 on GitHub (Mar 27, 2025).

NetBox version

v4.2.6

Feature type

Data model extension

Proposed functionality

With the JSON schema infrastructure added to support #19002, I feel like this is finally an appropriate time to make this feature request. A proposal to use regex for the same purpose was previously made in #9236, but I agree that was not a good option. Therefore, my proposal is to add a new schema JSONField to the CustomField data model and add JSONSchema validation when cleaning custom fields. This would be an optional field, just like other custom field validation, to allow for data structure validation only if desired. The addition of the dynamic form rendering when a schema is present would be an interesting further enhancement. A modal or other reference to the schema when entering data would also be a useful solution.

Use case

We have found in our environment a growing interest in leveraging JSON type custom fields to capture some more complex data structures. These are often then fed into scripts or other integrations, so their structure is critical. While custom validators can be used, we have not found that solution to be scalable or user-friendly, as it can often be difficult when working in the UI to remember the exact syntax that is expected and it requires backend administration when changes need to be made.

Database changes

Add an optional schema JSONField to the CustomField data model.

External dependencies

This should only need to leverage the newly introduced jsonschema dependency.

Originally created by @sleepinggenius2 on GitHub (Mar 27, 2025). ### NetBox version v4.2.6 ### Feature type Data model extension ### Proposed functionality With the JSON schema infrastructure added to support #19002, I feel like this is finally an appropriate time to make this feature request. A proposal to use regex for the same purpose was previously made in #9236, but I agree that was not a good option. Therefore, my proposal is to add a new `schema` JSONField to the `CustomField` data model and add JSONSchema validation when cleaning custom fields. This would be an optional field, just like other custom field validation, to allow for data structure validation only if desired. The addition of the dynamic form rendering when a schema is present would be an interesting further enhancement. A modal or other reference to the schema when entering data would also be a useful solution. ### Use case We have found in our environment a growing interest in leveraging JSON type custom fields to capture some more complex data structures. These are often then fed into scripts or other integrations, so their structure is critical. While custom validators can be used, we have not found that solution to be scalable or user-friendly, as it can often be difficult when working in the UI to remember the exact syntax that is expected and it requires backend administration when changes need to be made. ### Database changes Add an optional `schema` JSONField to the `CustomField` data model. ### External dependencies This should only need to leverage the newly introduced `jsonschema` dependency.
Author
Owner

@jnovinger commented on GitHub (Mar 27, 2025):

As long as we contain this to only custom JSON fields, this seems appropriate to add.

@jnovinger commented on GitHub (Mar 27, 2025): As long as we contain this to only custom JSON fields, this seems appropriate to add.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10954