Skip to content

Add JSON schema validation for JSON custom fields #19025

@sleepinggenius2

Description

@sleepinggenius2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity: mediumRequires a substantial but not unusual amount of effort to implementneeds milestoneAwaiting prioritization for inclusion with a future NetBox releasenetboxstatus: backlogAwaiting selection for worktype: featureIntroduction of new functionality to the application

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions