Convert JSON to PostgreSQL
CREATE TABLE — free & instant
Paste a JSON object or array and get a PostgreSQL CREATE TABLE statement with automatically inferred column types, JSONB support for nested data, and ready-to-run DDL. No upload, no signup.
Open JSON to PostgreSQL ConverterFrom JSON to PostgreSQL DDL in seconds
No server. No risk. No nonsense.
100% Private
Your JSON never leaves your device. There is no server receiving your data — everything runs in the browser.
Instant DDL
Type inference and DDL generation happen instantly. No waiting for a backend response.
PostgreSQL Native
Output uses PostgreSQL-specific types like JSONB, NUMERIC, and TEXT — not generic SQL.
Related JSON tools
Common questions answered
How does JSON to PostgreSQL DDL conversion work?
The converter analyzes your JSON structure and infers PostgreSQL column types for each field. Strings become TEXT or VARCHAR, numbers become INTEGER or NUMERIC, booleans become BOOLEAN, and nested objects or arrays become JSONB columns. The result is a ready-to-run CREATE TABLE statement.
What PostgreSQL types are generated from JSON?
The converter maps JSON types to PostgreSQL types: strings to TEXT, integers to INTEGER, floating-point numbers to NUMERIC, booleans to BOOLEAN, null-only fields to TEXT (nullable), and nested objects or arrays to JSONB — PostgreSQL's native JSON binary format for efficient querying.
How are JSON arrays handled in the PostgreSQL output?
JSON arrays are converted to JSONB columns in PostgreSQL, which allows you to use PostgreSQL's powerful JSON operators (@>, ->, ->>, jsonb_array_elements) to query array contents. This preserves the full structure while keeping the schema flat.
Can I use JSONB columns for nested objects?
Yes. Any nested JSON object is mapped to a JSONB column. PostgreSQL JSONB supports indexing (GIN indexes), containment queries, and path-based access — making it ideal for semi-structured data that doesn't need its own relational table.
Is my data safe when converting JSON to PostgreSQL?
Completely safe. The conversion runs 100% in your browser. Your JSON data is never sent to a server, never stored, and never logged. You can verify this by disconnecting from the internet — the tool continues to work.
Converting JSON for PostgreSQL
PostgreSQL has first-class JSON support with its jsonb column type, operators (-> and ->>), and rich JSON functions. This tool generates PostgreSQL-specific SQL: CREATE TABLE with jsonb columns, INSERT with proper casting, and example queries using native JSON operators.
The converter produces two outputs: a relational mapping (each key becomes a column) and a jsonb mapping (entire document in one column). The relational approach suits frequently queried fields; jsonb preserves flexibility for semi-structured data. Output includes GIN indexing suggestions for fast JSON queries.
{
"name": "Alice",
"age": 30,
"meta": {
"roles": ["admin"],
"joined": "2024-01-15"
}
}
-- Relational CREATE TABLE users ( name TEXT NOT NULL, age INTEGER, meta JSONB ); -- Query jsonb SELECT meta->>'joined' FROM users WHERE meta->'roles' ? 'admin';
Get the most out of this tool
- Use jsonb over json in PostgreSQL — jsonb is binary, faster to query, and supports indexing.
- Create GIN indexes on jsonb: CREATE INDEX idx ON t USING GIN (data jsonb_path_ops) for fast queries.
- Use -> for JSON objects and ->> for text extraction: data->>'name' returns text for WHERE clauses.
Ready to generate your PostgreSQL schema?
Free forever. No signup. Works offline.
Convert JSON to PostgreSQL NowPostgreSQL schema generation from JSON
PostgreSQL is the most feature-rich open-source relational database, and it offers exceptional JSON support through its JSON and JSONB column types. However, for most applications, mapping JSON data to proper relational tables with typed columns produces better query performance, clearer schemas, and more efficient storage than storing JSON blobs. This converter helps you design the relational schema from a JSON sample, generating CREATE TABLE statements with PostgreSQL-specific types.
PostgreSQL's type system is much richer than standard SQL. The converter maps JSON strings to TEXT or VARCHAR(n), JSON integers to INTEGER or BIGINT (depending on range), JSON floats to NUMERIC (for precision) or FLOAT8 (double precision), JSON booleans to BOOLEAN, and JSON null to NULL in any column type. PostgreSQL additionally supports UUID, TIMESTAMP WITH TIME ZONE, INET (IP addresses), JSONB (binary JSON), and ARRAY types — the converter infers these from field naming conventions when the pattern is recognizable.
The JSONB column type is PostgreSQL's most powerful feature for semi-structured data. Unlike TEXT storage of JSON, JSONB stores a parsed binary representation that supports GIN indexes for fast key and value lookups, containment operators (@> for "contains"), and path operators for querying nested values. If your JSON data has fields that are themselves JSON objects with variable structure, storing them as JSONB while keeping stable fields as regular typed columns is the best of both worlds.
Primary key generation is a critical schema design decision not determinable from a JSON sample alone. The converter adds a SERIAL or BIGSERIAL primary key column (PostgreSQL's auto-incrementing integer) as a default, or uses UUID as the primary key if the JSON sample contains a field named "id" with UUID-format values. Review the generated DDL and adjust the primary key type based on your application's identity requirements.
Foreign key relationships between tables are inferred from field naming patterns — a field named "user_id" in a JSON object that also has a "users" array is likely a foreign key reference. The converter includes comments suggesting potential foreign key relationships but does not generate them automatically, since referential integrity constraints require knowledge of the full schema that cannot be inferred from a single JSON sample.
PostgreSQL indexes are not generated by the converter but are critical for performance. Every column used in WHERE clauses, JOIN conditions, and ORDER BY should have an index. The generated DDL is a starting point — after reviewing it, add CREATE INDEX statements for the columns you will query most frequently. GIN indexes on JSONB columns, BRIN indexes on timestamp columns for time-series data, and partial indexes for common filter conditions are all PostgreSQL-specific optimizations worth considering.
When developers use this tool
Additional frequently asked questions
Should I use JSON or JSONB for semi-structured data in PostgreSQL?
Always use JSONB over JSON for new schemas. JSONB stores a parsed binary representation that is faster to query, supports GIN indexing, and supports the full suite of JSON operators. The JSON type stores the raw text and re-parses it on every access. JSON has one advantage: it preserves key order and duplicate keys — which almost never matters in practice.
What PostgreSQL type should I use for timestamps?
Use TIMESTAMP WITH TIME ZONE (timestamptz) for all datetime storage. PostgreSQL stores timestamptz internally in UTC and converts to the session's timezone on output. This prevents timezone confusion bugs that occur with plain TIMESTAMP (no timezone) when the database server and application run in different timezones. For date-only values, use the DATE type.
How do I store JSON arrays in PostgreSQL?
For arrays of primitive values (string arrays, integer arrays), PostgreSQL's native array types (TEXT[], INTEGER[]) provide better performance and query support than JSONB arrays. For arrays of objects with variable structure, use JSONB. For arrays of objects with fixed structure, consider a separate normalized table with a foreign key — this enables efficient joins and proper indexing.
Can I run the generated DDL directly against PostgreSQL?
The generated DDL is syntactically valid PostgreSQL and can be run directly. However, always review it before running — the type inference is based on a single JSON sample and may not account for edge cases in your full dataset. Check that string lengths are appropriate, that numeric types have sufficient range, and that any suggested JSON columns are intentional rather than conversion failures.