
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
django-validated-jsonfield
Advanced tools
django_validated_jsonfield is an inplace replacement for django JSONField which is validated against a json_schema
Replace your JSONField import
from django.db.models import JSONField` or `from django.contrib.postgres.fields import JSONField
by
from django_validated_jsonfield import ValidatedJSONField as JSONField
class MyModel(models.Model):
_data_schema = {
"type": "object",
"properties": {
"en": {"type": ["string", "null"], "default":"", "example":"Name", "title":"Name"}
"fr": {"type": ["string", "null"], "default":"", "example":"Nom", "title":"Nom"}
},
"default": {}, #note the top level default
"additionalProperties": False,
}
data = JSONField(schema=_data_schema, editable=True)
replace
from rest_framework.serializers import JSONField
by
from django_validated_jsonfield import ValidatedJSONFieldSerializer as JSONField
The updated JSONField expect to receive a "schema" and "json_validator_cls" argument at initilization.
Add the ValidatedJsonModelSerializerMixin to your ModelSerializer classes.
from django_validated_jsonfield import ValidatedJsonModelSerializerMixin
class MyModelSerializer(ValidatedJsonModelSerializerMixin, serializers.ModelSerializer):
class Meta:
model = MyModel
exclude = []
add the following block to your django settings.py file
from django_validated_jsonfield.yasg import DEFAULT_FIELD_INSPECTORS
SWAGGER_SETTINGS = {
'DEFAULT_FIELD_INSPECTORS': DEFAULT_FIELD_INSPECTORS
}
you should see the json field of your model being documented in Swagger
if the default field is provided in the json schema, the data will be initialized to the default value (if missing). The feature works well only parents of nested fields in the json schema have a default themselves (to list or dict) --> Note the "top level default" in the example above.
FAQs
Add a schema with validation to your jsonfield
We found that django-validated-jsonfield demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.