ORJSON Renderer¶
Django Ninja AIO uses an internal ORJSON-based renderer for fast JSON serialization. It is enabled automatically when you use NinjaAIO — no configuration required.
-
Fast
ORJSON is significantly faster than Python's built-in
jsonmodule -
Configurable
Customize serialization options via Django settings
-
Passthrough
HttpResponseobjects bypass the renderer automatically
Configuration¶
Configure serialization options via Django settings:
Available options¶
| Option | Description |
|---|---|
OPT_INDENT_2 |
Pretty-print with 2-space indentation |
OPT_NON_STR_KEYS |
Allow non-string dict keys |
OPT_SORT_KEYS |
Sort dictionary keys in output |
OPT_NAIVE_UTC |
Serialize naive datetimes as UTC |
OPT_UTC_Z |
Use Z suffix instead of +00:00 for UTC |
OPT_OMIT_MICROSECONDS |
Omit microseconds from datetime output |
Tip
Combine options with the | (bitwise OR) operator. See the orjson documentation for the full list.
HttpResponse Passthrough¶
The renderer automatically detects when you return a Django HttpResponse (or any HttpResponseBase subclass) and passes it through without JSON serialization.
Important
When returning an HttpResponse directly, set the status parameter on the HttpResponse itself. Do not use a tuple return like return 200, HttpResponse(...) — the response bypasses the renderer entirely.
Supported Types¶
ORJSON natively handles types that Python's json module cannot:
| Type | Behavior |
|---|---|
datetime, date, time |
ISO 8601 format |
UUID |
String representation |
Decimal |
Serialized as number |
numpy arrays |
Serialized as lists |
dataclass instances |
Serialized as dicts |
bytes |
Not supported — convert to string first |
See Also¶
-
APIViewSet
Auto-generated CRUD endpoints using orjson rendering
-
ModelSerializer
Schema generation for fast JSON serialization
-
Quick Start
Get up and running in minutes