Convert JSON to MySQL
Drop your JSON file to get a MySQL script with CREATE TABLE and INSERT statements. Each column gets a type, and every fix is listed with its row and column.
4 rows converted, 2 fixes, none rejected
| Row | ||||||
|---|---|---|---|---|---|---|
| 2 | 000481 | Peña Muñoz | 2024-02-03T10:15:00Z | 1234.5 | true | |
| 3 | 000482 | José Ángel Ruiz | 2024-02-15T16:40:00Z | 99.9 | false | Entrega en la tarde |
| 4 | 000483 | Zoë Ortíz | 2024-02-29T09:05:00Z | 12 | true | |
| 5 | 000484 | Ñuño Castañeda | 2024-03-11T13:30:00Z | 980.75 | sí | Factura con "RFC" |
-- Written by IntoSQL for MySQL.
SET NAMES utf8mb4;
SET SESSION sql_mode = REPLACE(@@sql_mode, 'NO_BACKSLASH_ESCAPES', '');
START TRANSACTION;
CREATE TABLE pedidos_2024 (
pedido varchar(8) NOT NULL,
cliente varchar(16) NOT NULL,
fecha datetime NOT NULL,
total decimal(6,2) NOT NULL,
pagado tinyint(1) NOT NULL,
notas varchar(32)
) DEFAULT CHARSET=utf8mb4;
INSERT INTO pedidos_2024 (pedido, cliente, fecha, total, pagado, notas) VALUES
('000481', 'Peña Muñoz', '2024-02-03 10:15:00', 1234.5, TRUE, NULL),
('000482', 'José Ángel Ruiz', '2024-02-15 16:40:00', 99.9, FALSE, 'Entrega en la tarde'),
('000483', 'Zoë Ortíz', '2024-02-29 09:05:00', 12, TRUE, NULL),
('000484', 'Ñuño Castañeda', '2024-03-11 13:30:00', 980.75, TRUE, 'Factura con "RFC"');
COMMIT;
Fixes
- Leading zeros kept in "pedido": 000481 stays 000481, stored as text.
- "pagado" holds yes and no words (sí), stored as boolean.
Your file is converted on this computer and never uploaded.
Other samples:
From JSON to MySQL, column by column
The sample above, pedidos_2024.json, as IntoSQL writes it for MySQL: what each column holds in the file, the type it gets and how its first value lands in the script.
| In the file | First value | Column | MySQL type | In the script |
|---|---|---|---|---|
| pedido | 000481 | pedido | varchar(8) | '000481' |
| cliente | Peña Muñoz | cliente | varchar(16) | 'Peña Muñoz' |
| fecha | 2024-02-03T10:15:00Z | fecha | datetime | '2024-02-03 10:15:00' |
| total | 1234.5 | total | decimal(6,2) | 1234.5 |
| pagado | true | pagado | tinyint(1) | TRUE |
| notas | - | notas | varchar(32) | NULL |
Load the script into MySQL
The download is a plain .sql file. Run it with MySQL's own tools.
From a terminal
mysql --default-character-set=utf8mb4 mydb < pedidos_2024.mysql.sqlThe script sets utf8mb4 itself; the flag makes the client send it the same way, so accents arrive intact.
From a database tool
In MySQL Workbench, choose File, Run SQL Script, and pick the file.
Without a scriptPro
IntoSQL Pro loads the file straight into MySQL from the desktop app or the command line, without writing a script.
intosql load pedidos_2024.json --into mysql://user@localhost/mydbWhat to know about JSON files and MySQL
What IntoSQL reads in JSON files
- The file can be an array of objects, an object that holds that array under a key such as data, or one object per line (NDJSON).
- Each key becomes a column. Objects and arrays inside a value are kept as JSON text.
- Numbers keep their exact digits, and ISO 8601 dates become dates or timestamps.
What to know about MySQL
- Yes and no values become tinyint(1). Text up to 255 characters is varchar; longer text is text, mediumtext or longtext by size.
- The script uses utf8mb4 and sets the SQL mode, so accents, emoji, backslashes and line breaks load as written.
- MySQL's datetime stores no time zone.
How each kind of value is stored in MySQL
| Value | MySQL |
|---|---|
| Yes and no | tinyint(1) |
| Whole numbers | int |
| Large whole numbers | bigint |
| Decimals | decimal(p,s)double |
| Floating-point numbers | double |
| Dates | date |
| Times of day | time(6)time |
| Dates with a time | datetime(6)datetime |
| Dates with a time and offset | datetime(6)datetime |
| Text | varchar(n)textmediumtextlongtext |
Questions about JSON to MySQL
Not answered here? Write to us from the contact page and a person replies. Contact page
How do I convert JSON to MySQL?
Drop your file on the converter at the top of this page. It finds the header, reads every value and writes the MySQL script, listing each fix it made. Download the script and run it with the mysql client.
What shape does the JSON file need?
An array of objects, an object that holds that array under a key such as data, or one object per line (NDJSON). Each key becomes a column.
Which MySQL types does it use?
Yes and no values become tinyint(1), whole numbers int, decimals decimal(p,s), dates date, dates with a time datetime(6) and text varchar(n). Sizes come from the longest value in each column.
Does it keep leading zeros in MySQL?
Yes. A code such as 000481 stays text, so MySQL stores it as varchar(8) and the script writes it as '000481'.
Can it load the data into MySQL without a script?
Yes, with IntoSQL Pro. The desktop app and the command line connect to MySQL and load the rows straight in, creating the table first.
How big can the JSON file be?
NDJSON, one object per line, is read as it streams in, so files of several gigabytes work in the browser. A JSON document is read whole, so its limit is the memory the browser gives this page. The desktop app and the command line take files of any size.