JSON to Laravel Migration
Generate Laravel migration PHP code from JSON data with auto-detected column types.
- Home
- > Web Dev >
- JSON to Laravel Migration
What is JSON to Laravel Migration?
JSON to Laravel Migration converts JSON data structures into Laravel migration PHP code. Each property in your JSON becomes a column in the migration with the appropriate column type automatically detected from the value.
This tool features:
- Auto-detected column types — Strings, integers, floats, booleans, dates, and JSON are detected automatically.
- Smart defaults — Values are used as default values in the generated migration.
- Configurable options — Customize table name, string length, and toggle ID, timestamps, soft deletes, and unsigned integers.
- Type inference — Date and datetime strings are detected and mapped to
date()anddateTime()column types.
Type Mapping Reference
| JSON Type | Laravel Column Type | Example |
|---|---|---|
"hello" |
string('col', 255) |
string('title', 255)->default('hello') |
42 |
integer('col') |
integer('age')->default(42) |
3.14 |
float('col') |
float('price')->default(3.14) |
true |
boolean('col') |
boolean('is_active')->default(true) |
"2024-01-15" |
date('col') |
date('join_date')->default('2024-01-15') |
"2024-01-15T10:30:00Z" |
dateTime('col') |
dateTime('created_at')->default('2024-01-15T10:30:00Z') |
{...} |
json('col') |
json('metadata')->nullable() |
[...] |
json('col') |
json('tags')->nullable() |
How to Use
- Paste your JSON — Copy and paste a JSON object into the input textarea. Each key becomes a column in the migration. Click Load Example to see sample data.
- Configure settings — Set the table name, string length, and toggle optional features like timestamps and soft deletes.
- Generate — Click Generate Migration to produce the migration PHP code.
- Copy or download — Use the copy button or click Download .php to save the migration file.
Frequently Asked Questions
How does type inference work?
Each JSON property value is analyzed to determine its column type. Strings become string, numbers become integer or float, booleans become boolean, objects and arrays become json. Date strings matching YYYY-MM-DD format become date, and datetime strings become dateTime.
Can I customize the migration class?
The migration uses a Laravel 11 anonymous class. The class name is derived from the table name using StudlyCase. Change the table name input to customize both the table name and class name.
Is this tool safe for sensitive data?
Yes. All processing happens entirely in your browser using JavaScript. Your JSON data is never uploaded to any server, stored in any database, or logged.