Skip to content

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.

Your file
jsonpedidos_2024.jsonSample file, 771 B
Your database

4 rows converted, 2 fixes, none rejected

Show
The first rows of pedidos_2024.json, with each fix marked
Row
2000481Peña Muñoz2024-02-03T10:15:00Z1234.5true
3000482José Ángel Ruiz2024-02-15T16:40:00Z99.9falseEntrega en la tarde
4000483Zoë Ortíz2024-02-29T09:05:00Z12true
5000484Ñuño Castañeda2024-03-11T13:30:00Z980.75sí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

  1. Leading zeros kept in "pedido": 000481 stays 000481, stored as text.
  2. "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 fileFirst valueColumnSQL Server typeIn the script
pedido000481pedidonvarchar(8)N'000481'
clientePeña Muñozclientenvarchar(16)N'Peña Muñoz'
fecha2024-02-03T10:15:00Zfechadatetimeoffset'2024-02-03T10:15:00+00:00'
total1234.5totaldecimal(6,2)1234.5
pagadotruepagadobit1
notas-notasnvarchar(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

ValueSQL Server
Yes and nobit
Whole numbersint
Large whole numbersbigint
Decimalsdecimal(p,s)
Floating-point numbersfloat
Datesdate
Times of daytime
Dates with a timedatetime2
Dates with a time and offsetdatetimeoffset
Textnvarchar(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.