← All tools
Free tool
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.
input.json
output.sql · root (2 rows) · root_address (2 rows) · root_orders (2 rows)
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
Related tools
Keep exploring
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.