Shard Tools

JSON to SQL

Turn a JSON array into SQL INSERT statements in your browser, with quotes escaped correctly.

Maintained by Roshan.

Use JSON to SQL

Converts JSON array of objects into SQL in this tab. Configuration files routinely hold hostnames, keys and credentials, so nothing here is sent anywhere.

Values are never retyped as numbers or booleansGuessing types is how a converter turns a postcode of 0123 into 123, or a literal string of false into a boolean. Values are carried across as they were written, and casting is left to you where it matters.

Explore developer and data tools

Find related browser-local tools for nearby tasks without starting another search.

Browse all developer and data tools

About JSON to SQL

Getting a handful of records into a database is a task with no good tool. Writing the INSERT statements by hand is tedious and error-prone, setting up a proper import pipeline is disproportionate for fifty rows, and the obvious shortcut - pasting values into a template - is exactly how SQL injection bugs and broken imports happen. The specific hazard is the apostrophe. A single quote inside a value terminates the string literal, so a customer called O'Brien turns a valid statement into a syntax error, or worse into a statement that runs and does something unintended. Escaping is handled properly here by doubling embedded quotes, which is the standard-conformant approach that every major database accepts.

Work through the input

  1. Each object in the array becomes one INSERT statement, with the column list taken from the union of keys across every record.
  2. A record missing a property gets NULL for that column rather than being written with fewer values, which would produce a statement that fails or, worse, shifts the data into the wrong columns.
  3. String values are wrapped in single quotes with any embedded quote doubled, which is the standard escape and is accepted by every major database.
  4. Numbers and booleans are written unquoted, since the source JSON genuinely declares those types, and null becomes the SQL keyword NULL rather than the text.
  5. The table name is yours to set, and it is sanitised to a safe identifier so an unusual name cannot produce broken or dangerous SQL.

When json to sql is useful

Seeding a development database

Convert a small fixture file into inserts and paste them into your migration or console. Check the column names line up with the schema first.

Loading an API response into a table

Take the JSON, generate the statements, and review them before running. Watch for date formats, which vary between databases.

Check the output

Questions about JSON to SQL

How are apostrophes handled?

By doubling them, which is the standard SQL escape. A name like O'Brien becomes 'O''Brien' and inserts correctly.

Does it create the table?

No. The statements assume the table exists. Only INSERT statements are produced.

What happens to missing properties?

They become NULL. Writing fewer values would shift the remaining data into the wrong columns, which is far worse than an explicit null.

How are nested objects handled?

They are written as JSON text in the value, which suits a JSON column and needs handling otherwise.

Should I run the output directly?

Review it first. It is generated from your data and intended to be read before being executed against anything real.

Related tools

JSON to CSV Converter

Convert JSON objects to UTF-8 CSV in your browser. Union columns, quote values, and protect formula-like strings.

CSV to JSON Converter

Convert CSV to a JSON array locally. Parse quoted commas, embedded newlines, BOM files, duplicate headers, sparse rows, and optional safe value types.

JSON to HTML Table

Turn a JSON array into a clean HTML table in your browser, with markup in the data escaped safely.