Support JSON custom fields #1815

Closed
opened 2025-12-29 17:19:21 +01:00 by adam · 3 comments
Owner

Originally created by @wrouesnel on GitHub (Jun 25, 2018).

Issue type

[x] Feature request
[ ] Bug report
[ ] Documentation

Environment

  • Python version: 3.6.4
  • NetBox version: 2.3.4

Description

To integrate Netbox with external systems more reliably, we would like to be able to store JSON structured data against objects with custom fields.

For our use case this is to support marking up our devices, IPs and networks which additional data to support custom tooling and to match metadata which maps to other systems.

To implement this, the proposal would be to add a "structured_data" field to the CustomFieldValue model, and a new CF_TYPE_JSON type for custom fields. CustomField's with JSON data would return the structured_data value rather then a deserialized value, which in the underlying database would be stored as a postgres JSONB type via the Django postgres JSON field.

To support data consistency, two additional fields for the CustomField would be added - json_schema as JSON and validate_json (a bool) to allow enforcing the structure of added JSON and using the django-jsonforms module to generate rich user frontends for custom fields in the UI. django-json-widget can be used to support free editing of schemas in the admin interface.

An early version of this proposal is already implemented here: https://github.com/wrouesnel/netbox/tree/json_custom_fields, the django-jsonforms requires some CSS work to fit nicely into the UI.

Originally created by @wrouesnel on GitHub (Jun 25, 2018). ### Issue type [x] Feature request <!-- An enhancement of existing functionality --> [ ] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> ### Environment * Python version: 3.6.4 * NetBox version: 2.3.4 <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description To integrate Netbox with external systems more reliably, we would like to be able to store JSON structured data against objects with custom fields. For our use case this is to support marking up our devices, IPs and networks which additional data to support custom tooling and to match metadata which maps to other systems. To implement this, the proposal would be to add a "structured_data" field to the CustomFieldValue model, and a new `CF_TYPE_JSON` type for custom fields. CustomField's with JSON data would return the `structured_data` value rather then a deserialized value, which in the underlying database would be stored as a postgres JSONB type via the Django postgres JSON field. To support data consistency, two additional fields for the CustomField would be added - `json_schema` as JSON and `validate_json` (a bool) to allow enforcing the structure of added JSON and using the `django-jsonforms` module to generate rich user frontends for custom fields in the UI. `django-json-widget` can be used to support free editing of schemas in the admin interface. An early version of this proposal is already implemented here: https://github.com/wrouesnel/netbox/tree/json_custom_fields, the django-jsonforms requires some CSS work to fit nicely into the UI.
adam closed this issue 2025-12-29 17:19:21 +01:00
Author
Owner

@DanSheps commented on GitHub (Jun 26, 2018):

#1349

@DanSheps commented on GitHub (Jun 26, 2018): #1349
Author
Owner

@alxnet commented on GitHub (Jun 29, 2018):

Hi, I've been thinking about migrating to netbox, but the tooling we use relies on JSON custom fields. I've been following the discussion on #1349 but as far as I could understand it has a different scope. In our case, we'd rather merge the context ourselves. Besides, some fields do not directly relate to configuration information, so we just need a placeholder for the json data and the ability to index and query it efficiently. I'm very new to netbox and I found it amazing to see this early implementation. Btw, what if instead of serialized_value we had a json_value to unify the custom field representation?

netbox=# select json_value,jsonb_typeof(json_value) from extras_customfieldvalue;
                          json_value                           | jsonb_typeof 
---------------------------------------------------------------+--------------
 {"employee": {"age": 30, "city": "New York", "name": "John"}} | object
 "my project"                                                  | string
 false                                                         | boolean
 10102                                                         | number
@alxnet commented on GitHub (Jun 29, 2018): Hi, I've been thinking about migrating to netbox, but the tooling we use relies on JSON custom fields. I've been following the discussion on #1349 but as far as I could understand it has a different scope. In our case, we'd rather merge the context ourselves. Besides, some fields do not directly relate to configuration information, so we just need a placeholder for the json data and the ability to index and query it efficiently. I'm very new to netbox and I found it amazing to see this early implementation. Btw, what if instead of serialized_value we had a json_value to unify the custom field representation? ``` netbox=# select json_value,jsonb_typeof(json_value) from extras_customfieldvalue; json_value | jsonb_typeof ---------------------------------------------------------------+-------------- {"employee": {"age": 30, "city": "New York", "name": "John"}} | object "my project" | string false | boolean 10102 | number ```
Author
Owner

@jeremystretch commented on GitHub (Jun 29, 2018):

Custom fields are not intended to store large amounts of data. Values are limited to 255 characters. #1349 will introduce config contexts in v2.4, which will support arbitrary data in JSON formats applied to a set of device/VMs (categorized by site, role, etc.). However, the attachment of arbitrary free-form data to individual objects is out of scope for NetBox.

@jeremystretch commented on GitHub (Jun 29, 2018): Custom fields are not intended to store large amounts of data. Values are limited to 255 characters. #1349 will introduce config contexts in v2.4, which will support arbitrary data in JSON formats applied to a set of device/VMs (categorized by site, role, etc.). However, the attachment of arbitrary free-form data to _individual_ objects is out of scope for NetBox.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1815