EUComply

How to Convert JSON to SQL INSERT Statements

August 24, 2026 · 5 min read · Try the free converter →

Migrating seed data, importing an API export into Postgres, loading fixtures — the job is always the same: take a JSON array of objects and turn it into INSERT statements your database will accept without a fight.

Method 1: CLI

Using transmute

$ cat users.json | qf --to sql --table users
INSERT INTO users (id, name, email) VALUES (1, 'Alice', '[email protected]');
INSERT INTO users (id, name, email) VALUES (2, 'Bob', '[email protected]');

Column names come from the first object's keys, types are preserved (numbers stay unquoted, strings get proper escaping), and --table names the target table. Pipe it straight into your database:

$ cat users.json | qf --to sql --table users | psql mydb

Using jq

$ jq -r '.[] | "INSERT INTO users VALUES (\(.id), \(.name), \(.email));"' users.json

This one-liner works only while your data stays simple. The moment a name contains an apostrophe (O'Brien) the generated SQL breaks — jq doesn't know SQL quoting rules. If any field is user-entered text, use a tool that escapes properly.

Method 2: Python

import json, sqlite3
rows = json.load(open("users.json"))
db = sqlite3.connect("app.db")
db.executemany(
    "INSERT INTO users (id, name, email) VALUES (?, ?, ?)",
    [(r["id"], r["name"], r["email"]) for r in rows],
)
db.commit()

The parameterized-queries route is the safest if you're inserting into SQLite directly — no string building at all. It only works when you control the database connection, though; if you need a .sql file to hand off, generate statements instead.

Gotchas That Corrupt Data

Convert JSON → SQL in one click

Transmute runs the conversion on your machine — paste it in, or script it from the command line. JSON, YAML, CSV, TOML and XML, fully offline.

Get Transmute Desktop — $19 one-time →   Or use the free web converter