Convert JSON to SQL Server
Drop your JSON file to get a SQL Server 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 SQL Server.
SET NOCOUNT ON;
BEGIN TRANSACTION;
CREATE TABLE pedidos_2024 (
pedido nvarchar(8) NOT NULL,
cliente nvarchar(16) NOT NULL,
fecha datetimeoffset NOT NULL,
total decimal(6,2) NOT NULL,
pagado bit NOT NULL,
notas nvarchar(32)
);
INSERT INTO pedidos_2024 (pedido, cliente, fecha, total, pagado, notas) VALUES
(N'000481', N'Peña Muñoz', '2024-02-03T10:15:00+00:00', 1234.5, 1, NULL),
(N'000482', N'José Ángel Ruiz', '2024-02-15T16:40:00+00:00', 99.9, 0, N'Entrega en la tarde'),
(N'000483', N'Zoë Ortíz', '2024-02-29T09:05:00+00:00', 12, 1, NULL),
(N'000484', N'Ñuño Castañeda', '2024-03-11T13:30:00+00:00', 980.75, 1, N'Factura con "RFC"');
COMMIT TRANSACTION;
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 SQL Server, column by column
The sample above, pedidos_2024.json, as IntoSQL writes it for SQL Server: 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 | SQL Server type | In the script |
|---|---|---|---|---|
| pedido | 000481 | pedido | nvarchar(8) | N'000481' |
| cliente | Peña Muñoz | cliente | nvarchar(16) | N'Peña Muñoz' |
| fecha | 2024-02-03T10:15:00Z | fecha | datetimeoffset | '2024-02-03T10:15:00+00:00' |
| total | 1234.5 | total | decimal(6,2) | 1234.5 |
| pagado | true | pagado | bit | 1 |
| notas | - | notas | nvarchar(32) | NULL |
Load the script into SQL Server
The download is a plain .sql file. Run it with SQL Server's own tools.
From a terminal
sqlcmd -S localhost -d mydb -f 65001 -i pedidos_2024.sql_server.sql-f 65001 reads the file as UTF-8, so accents and ñ arrive as written.
From a database tool
In SQL Server Management Studio or Azure Data Studio, open the file and choose Execute.
What to know about JSON files and SQL Server
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 SQL Server
- Text is nvarchar with N'...' values, so accents survive; text over 4000 characters becomes nvarchar(max).
- Yes and no values become bit, and dates with an offset become datetimeoffset.
- Long values are written in pieces, so sqlcmd and SQL Server Management Studio accept the script.
How each kind of value is stored in SQL Server
| Value | SQL Server |
|---|---|
| Yes and no | bit |
| Whole numbers | int |
| Large whole numbers | bigint |
| Decimals | decimal(p,s) |
| Floating-point numbers | float |
| Dates | date |
| Times of day | time |
| Dates with a time | datetime2 |
| Dates with a time and offset | datetimeoffset |
| Text | nvarchar(n)nvarchar(max) |
Questions about JSON to SQL Server
Not answered here? Write to us from the contact page and a person replies. Contact page
How do I convert JSON to SQL Server?
Drop your file on the converter at the top of this page. It finds the header, reads every value and writes the SQL Server script, listing each fix it made. Download the script and run it with sqlcmd.
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 SQL Server types does it use?
Yes and no values become bit, whole numbers int, decimals decimal(p,s), dates date, dates with a time datetime2 and text nvarchar(n). Sizes come from the longest value in each column.
Does it keep leading zeros in SQL Server?
Yes. A code such as 000481 stays text, so SQL Server stores it as nvarchar(8) and the script writes it as N'000481'.
Can it load the data into SQL Server without a script?
No. Download the script and run it with sqlcmd. Loading without a script works for PostgreSQL, MySQL, MariaDB and SQLite, from the desktop app or the command line.
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.