Skip to content
cosmodev ~/tools/json-to-sql

JSON sang SQL INSERT

Data & DevOps

Chuyển mảng JSON các đối tượng thành các câu lệnh SQL INSERT. Thoát chuỗi đúng chuẩn, xử lý null, boolean, số, đối tượng lồng nhau và chèn nhiều dòng.

Biến thể SQL

(Tài liệu bằng tiếng Anh)

What it does

Convert a JSON array of objects into SQL INSERT statements. Columns are the union of keys across all rows; values are escaped per dialect: strings double their single quotes ('O''Brien'), MySQL additionally escapes backslashes, MySQL renders booleans as 1/0, null stays NULL, numbers stay bare, and nested objects/arrays serialize to JSON text. Identifier quoting follows the dialect: double quotes for standard SQL and Postgres, backticks for MySQL. 100% client-side.

How to use it

  1. Paste a JSON array of objects (or a single object) into JSON — a sample is prefilled.
  2. Set the Table name and pick a Dialect: SQL, MySQL, or Postgres.
  3. The INSERTs render live on the right with the row count in the header.
  4. Copy them, or Download as insert.sql.

Examples

Basic insert with escaping — [{"id":1,"name":"O'Brien"}], table users →

INSERT INTO "users" ("id", "name") VALUES
  (1, 'O''Brien');

Mixed value types — [{"id":2,"ok":false,"note":null,"meta":{"a":1}}] →

INSERT INTO "users" ("id", "ok", "note", "meta") VALUES
  (2, FALSE, NULL, '{"a":1}');

MySQL dialect — same input renders INSERT INTO `users` (`id`, `ok`) VALUES (2, 0); (backtick identifiers, boolean as 0/1).

Missing keys across rows — a row without a column the other rows have gets NULL in that position.

Good to know

  • Private: conversion is local — nothing leaves the browser.
  • One multi-row INSERT ... VALUES (...), (...) statement per conversion, not one statement per row.
  • Postgres output also works for SQLite in most cases; pick SQL for the conservative baseline.
  • Related tools: JSON Formatter, JSON to TypeScript.
Mã nguồn14 ngôn ngữ

100% phía client · dữ liệu của bạn không bao giờ rời khỏi trình duyệt. Thấy hữu ích? Chia sẻ với đồng nghiệp của bạn.