Serializers¶
orjson-powered copies of Django’s built-in JSON serializers, for use with dumpdata and loaddata.
They will also be used automatically for json/jsonl format fixtures in TransactionTestCase.fixtures and the testserver command.
Register the serializers by adding entries to SERIALIZATION_MODULES in your settings:
SERIALIZATION_MODULES = {
"json": "django_orjson.serializers.json",
"jsonl": "django_orjson.serializers.jsonl",
}
Then use them like the built-in serializers:
$ python manage.py dumpdata --format json myapp > data.json
$ python manage.py loaddata --format json data.json
$ python manage.py dumpdata --format jsonl myapp > data.jsonl
$ python manage.py loaddata --format jsonl data.jsonl
Or programmatically:
from django.core import serializers
data = serializers.serialize("json", queryset)
for obj in serializers.deserialize("json", data):
obj.save()
The serializers’ output is compatible with Django’s standard JSON deserializer, except that when indent is passed, the output uses orjson’s two-space indentation regardless of the value specified.