Skip to content
OddsockLocal
Local
Source text
{
  "color": "red",
  "count": 2
}
1 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste a JSON array of objects. A single object is not enough.
  2. Set Table name.
  3. Read the column list from the object keys.
  4. Copy the INSERT. Add the table yourself if it does not exist yet.

What is JSON to SQL?

JSON to SQL expects an array of objects and writes one INSERT. [{"Item":"Notebook","Quantity":12},{"Item":"Pen","Quantity":4}] with table name records becomes INSERT INTO "records" ("Item", "Quantity") VALUES\n('Notebook', 12),\n('Pen', 4);. There is no CREATE TABLE. If you need the table statement and the type guess, start from CSV on the other page.

Read more

Keys are the column list, in the order they are collected from the objects. A later object that lacks a key gets NULL in that position. Strings are single-quoted with quotes doubled. Numbers and booleans are bare, booleans written TRUE or FALSE. A JSON object that is not an array, or an empty array, is an error.

The INSERT builder on the next page runs the same statement shape. Use this one when the document already exists as JSON. Use the builder when you are typing seed rows. Neither page offers a MySQL or SQL Server dialect: quoting is double quotes for identifiers.

Use cases

  • An API returned an array of two products and you want an INSERT without hand-quoting Notebook.
  • A row is missing a key and you want NULL there rather than a shifted column.
  • You already have a table, so a CREATE TABLE statement would be in the way.
  • You need to see booleans land as TRUE and FALSE, not as the strings 'true' and 'false'.

Two objects, insert only

Table name records. [{"Item":"Notebook","Quantity":12},{"Item":"Pen","Quantity":4}]

INSERT INTO "records" ("Item", "Quantity") VALUES\n('Notebook', 12),\n('Pen', 4);

Why use Oddsock

No CREATE TABLE, on purpose. The CSV page is the one that invents column types and a table.

Related tools

Using this tool

This page only inserts. CSV to SQL writes CREATE TABLE and infers TEXT or NUMERIC. If the table exists, you do not want a second definition.