JSON to SQL converter
Paste a JSON object or array and get PostgreSQL CREATE TABLE statements with inferred types, plus INSERTs. Nested objects become properly linked child tables.
CREATE TABLE root (
id integer PRIMARY KEY NOT NULL,
name text NOT NULL,
email text,
is_active boolean NOT NULL,
orders jsonb NOT NULL
);
CREATE TABLE root_address (
id SERIAL PRIMARY KEY NOT NULL,
city text NOT NULL,
postcode text NOT NULL,
root_id integer NOT NULL
);
CREATE TABLE root_orders (
id SERIAL PRIMARY KEY NOT NULL,
order_id text NOT NULL,
total double precision NOT NULL,
placed_at timestamptz NOT NULL,
root_id integer NOT NULL
);
ALTER TABLE root_address ADD CONSTRAINT fk_root_address_root_id FOREIGN KEY (root_id) REFERENCES root (id);
ALTER TABLE root_orders ADD CONSTRAINT fk_root_orders_root_id FOREIGN KEY (root_id) REFERENCES root (id);
INSERT INTO root (id, name, email, is_active, orders) VALUES
(1, 'Ada Lovelace', 'ada@example.com', TRUE, '[{"order_id":"a1","total":49.99,"placed_at":"2024-01-15T10:00:00Z"},{"order_id":"a2","total":19.5,"placed_at":"2024-02-01T12:30:00Z"}]'),
(2, 'Grace Hopper', NULL, TRUE, '[]');
INSERT INTO root_address (id, city, postcode, root_id) VALUES
('1', 'London', 'W1A 1AA', 1),
('2', 'New York', '10001', 2);
INSERT INTO root_orders (id, order_id, total, placed_at, root_id) VALUES
('1', 'a1', 49.99, '2024-01-15T10:00:00Z', 1),
('2', 'a2', 19.5, '2024-02-01T12:30:00Z', 1);Frequently asked questions
How are nested JSON objects turned into tables?
Each nested object and each array of objects becomes its own child table named parent_key, with a foreign-key column back to the parent row. Arrays of plain values and empty arrays collapse to jsonb. A natural id field becomes the primary key when its values are unique; otherwise the tool adds a SERIAL id.
Is it free?
Yes, completely free with no signup. Conversion runs in your browser; inputs up to 500KB convert instantly and INSERT output caps at 1000 rows with a note.
Is my data uploaded anywhere?
No. Parsing, type inference, and SQL generation run entirely in your browser. Your JSON is never uploaded, stored, or logged.
Which PostgreSQL types are inferred?
integer, bigint, double precision, boolean, date, timestamptz, uuid, text, and jsonb, with nullability inferred from nulls and missing keys. Mixed-type columns safely fall back to text or jsonb.
Can I turn the result into an ER diagram?
Yes. Click Visualize this schema to open the generated tables, including the flattened child tables and their foreign keys, as an interactive ER diagram.
Related tools
Turn it into an ER diagram
Paste your PostgreSQL connection string and get an interactive ER diagram of your own schema in under 10 seconds. No signup required.