How to Import JSON into MySQL or PostgreSQL as Rows

Published 24 November 2026 · 7 min read

You have a JSON file from an API or an export, and you want it in a database table. Some databases can load JSON directly, but often the simplest path is plain SQL: a CREATE TABLE statement and a batch of INSERT statements you can run anywhere. This guide covers the decisions that matter.

Start with the shape

SQL expects rows and columns, so the best input is an array of objects with similar keys.

[
  {"id": 101, "name": "Ana", "active": true, "joined": "2026-03-01"},
  {"id": 102, "name": "Ben", "active": false, "joined": null}
]

Each object becomes a row. The columns are the union of all keys, so a key missing from some objects simply becomes NULL for those rows.

Choosing column types

JSON valueTypical column
Whole numberINTEGER, or BIGINT if values are large
Decimal numberDECIMAL for money, DOUBLE for measurements
true or falseBOOLEAN (TINYINT(1) in MySQL, BIT in SQL Server)
TextVARCHAR or TEXT
Date or timestamp textDATE or TIMESTAMP, if every value has the same format
Object or arrayJSON or JSONB column, or flatten into several columns

A column with mixed types, such as numbers in some rows and text in others, should be text. Money is better stored as DECIMAL than as a floating point number, which cannot represent values like 0.10 exactly.

NULL is not an empty string

JSON null should become SQL NULL. An empty string "" is a real value and should stay an empty string. Mixing them up changes how counts, filters and joins behave.

Big IDs and exact numbers

JavaScript reads numbers as 64-bit floating point, so an integer above 9007199254740991 can be silently rounded. If your IDs are that large, use a tool that keeps the digits as written, and give the column BIGINT or a text type.

Nested objects and arrays

You have two choices. Flatten them into columns such as address_city, which works well when the structure is fixed. Or keep them whole in a JSON column, which suits arrays and irregular data and can still be queried with the database JSON functions. See flatten nested JSON into CSV for when flattening makes sense.

Escaping and safety

Text must be escaped so a name like O’Brien does not end the string early. Standard SQL doubles the quote, and MySQL also treats backslash as an escape character in strings. Generated statements are fine for trusted data, but if the JSON comes from users, load it through a parameterized import rather than running pasted SQL.

Batching and transactions

  • Insert many rows per statement, for example 100 to 1000, instead of one statement per row.
  • Wrap the load in a transaction so a failure leaves no half-loaded table.
  • Create the table first, and drop it only when you mean to reload.

Generate the SQL

The JSON to SQL converter infers the column types, handles NULLs and escaping, and writes the CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server. It runs in your browser, so your data is not uploaded. If the JSON is not valid, run it through the JSON formatter first.