What is JSON to Django Model Generator?
Django's ORM maps Python classes to database tables through model definitions — each class inherits from `models.Model`, and each class attribute becomes a database column with a specific field type. This generator inspects your JSON data (a single object or an array of objects for better cross-record type inference), determines the appropriate Django field type for each property, and produces a complete model class with a `Meta` inner class and a `__str__` method. It applies Python naming conventions by converting camelCase JSON keys to snake_case (`userName` → `user_name`), detects ISO date strings and maps them to `DateField` or `DateTimeField`, recognizes email patterns, infers `DecimalField` for string values that look like prices (`"29.99"`), and generates `ForeignKey` references for keys ending with `_id`. The app name prefix is used for both `db_table` naming and ForeignKey references, following Django's convention for avoiding table name collisions across apps.
How to Use
- Set the Django app name prefix (e.g. myapp) — this is used for ForeignKey references and db_table naming to avoid collisions in multi-app projects
- Paste your JSON data into the input area — provide an array of objects for better type inference across multiple records
- Click "Generate Django Models" to produce a complete model class with field definitions, Meta class, and __str__ method
- Copy the output into your models.py file and adjust max_length values and default options to match your business rules
- Run python manage.py makemigrations and python manage.py migrate to create the database table from the generated model
Why Use This Tool?
Tips & Best Practices
- Provide an array of JSON objects rather than a single object — the generator examines all records to produce more accurate field types and max_length estimates
- String values that look like decimal prices (e.g. "29.99") are automatically mapped to DecimalField with max_digits=10 and decimal_places=2 — adjust these for your currency requirements
- Long text fields (over 100 characters in the sample) are mapped to TextField with blank=True, while shorter strings get CharField with an estimated max_length
- The app name prefix follows Django convention for ForeignKey references (e.g. "myapp.Category") — make sure the referenced model exists in the same app or use the full app.Model path
- After pasting the generated model, review nullable fields — the generator adds blank=True, null=True for fields with null values, but you may want to add default values instead
Frequently Asked Questions
How does JSON map to Django field types?
JSON strings map to CharField (short text) or TextField (over 100 chars), integers map to IntegerField, floats map to DecimalField, booleans map to BooleanField, ISO date strings map to DateField or DateTimeField, null values produce blank=True and null=True, and keys ending with _id generate ForeignKey references. String values matching the decimal pattern (e.g. "29.99") are mapped to DecimalField.
When should I avoid using this generator?
Skip this tool if you need Django model inheritance, multi-table inheritance, many-to-many fields, or custom managers — the generator produces a flat single-table model. Also avoid it if your project uses Django REST Framework serializers with custom field mappings that differ from the model fields.
What is the app name prefix for?
The app name prefix is used in ForeignKey references (e.g., "myapp.Category") and in the db_table Meta option (e.g., "myapp_item"). This follows Django convention for avoiding table name collisions across apps in a multi-app project.
How are field names converted?
JSON keys are converted to snake_case following Python PEP 8 naming conventions. For example, "userName" becomes "user_name", "isActive" becomes "is_active". The id field is preserved as-is since Django reserves it as the default primary key.
Can I use this with an existing Django project?
Yes. Copy the generated model into your models.py file, adjust field options as needed (max_length, default values, etc.), then run python manage.py makemigrations and python manage.py migrate to create the database table. If the table already exists, use --fake-initial to skip the creation.
Is my data sent to a server?
No. All type inference and code generation run entirely in your browser. Your JSON data never leaves your device — no network requests, no server-side processing, and no data retention.
Real-world Examples
E-commerce product model
Generate a Django model for a product catalog with price detection, category foreign key, and proper field types from an array of product records.
[
{
"id": 1,
"name": "Wireless Mouse",
"price": "29.99",
"category_id": 5,
"description": "Ergonomic wireless mouse with USB receiver",
"inStock": true,
"created_at": "2024-01-15T10:30:00Z"
},
{
"id": 2,
"name": "Mechanical Keyboard",
"price": "89.99",
"category_id": 5,
"description": "Cherry MX Blue switches",
"inStock": false,
"created_at": "2024-02-20T14:15:00Z"
}
]from django.db import models
class Product(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=40)
price = models.DecimalField(max_digits=10, decimal_places=2)
category_id = models.ForeignKey("myapp.Category", on_delete=models.CASCADE)
description = models.TextField(blank=True)
in_stock = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = 'myapp_product'
verbose_name = 'item'
verbose_name_plural = 'items'
def __str__(self):
return self.nameUser profile model with nullable fields
Create a Django model for user profiles with optional bio and avatar fields.
{
"id": 1,
"username": "alice",
"email": "alice@example.com",
"bio": null,
"avatar": null,
"is_active": true
}from django.db import models
class User(models.Model):
id = models.AutoField(primary_key=True)
username = models.CharField(max_length=100)
email = models.CharField(max_length=255, blank=True, null=True)
bio = models.CharField(max_length=255, blank=True, null=True)
avatar = models.CharField(max_length=255, blank=True, null=True)
is_active = models.BooleanField(default=False)
class Meta:
db_table = 'myapp_user'
verbose_name = 'item'
verbose_name_plural = 'items'
def __str__(self):
return self.username