How to use the SQL query tool for CSV and JSON
Load CSV, TSV, JSON, or JSONL files, then query the generated table names with read-only SQL. The page reads each file with File.text(), keeps the source file unchanged, and lets you export the last result as CSV, JSON, or SQL text.
- Drop one or more CSV, TSV, JSON, or JSONL files here, or choose
browse files. - Check
Loaded tablesandInferred schemafor the generated table and column names. - Write a
SELECTstatement inQuery, or choosePreview a table,Group + count,Join two tables, orAggregate + HAVING. - Review the result table, then choose
Export CSV,Export JSON, orExport SQL textwhen rows are available.
How files become tables for SQL queries
CSV and TSV use the first row for column names. JSON accepts an array of records, an object with a non-empty array of records, or one object as a single record. JSONL and NDJSON read one JSON value per non-empty line. Missing fields and empty delimited fields become NULL. Nested JSON values become JSON text.
The table name comes from the filename. The extension is removed, punctuation becomes underscores, and the name is lowercased. A name that starts with a number gets a t_ prefix. Duplicate names receive _2, _3, and so on, so check Loaded tables before writing the query.
What Inferred schema and results show
Inferred schema checks up to 500 rows per column and displays the dominant type, such as integer, number, boolean, date, text, or empty. Mixed values can change that label. The query reports an unknown column as an error, and a shared unqualified column in a join is reported as ambiguous.
What SQL the query tool accepts
Write SELECT queries with expressions, aliases, DISTINCT, WHERE, INNER JOIN, LEFT JOIN, GROUP BY, HAVING, ORDER BY, LIMIT, and OFFSET. Aggregate functions include COUNT, SUM, AVG, MIN, and MAX. Scalar functions include UPPER, LOWER, LENGTH, ROUND, ABS, TRIM, LTRIM, RTRIM, CONCAT, COALESCE, SUBSTR, SUBSTRING, and REPLACE.
SELECT column_a, COUNT(*) AS n
FROM table1
GROUP BY column_a
ORDER BY n DESC;
The result has columns named column_a and n. In a join, write table.column when more than one table has the same column name. The parser accepts one statement beginning with SELECT. It rejects INSERT, UPDATE, DELETE, subqueries, window functions, and database commands.
The result table shows at most the first 500 rows, while exports include every row in the last result. When a query returns zero rows, the export controls stay hidden.
Where querying CSV and JSON fits
For example, group orders.csv by a category column, count each group, and export the returned rows as CSV. To combine files, join the table with id to the table with table1_id in the ON condition.
JSONL works for one-record-per-line data. Use WHERE to select records and export them as JSON. With TSV, apply TRIM or REPLACE inside a SELECT; the loaded source remains unchanged.
When to use this tool or Database Analyze Tools
Choose this page when your data is in CSV, TSV, JSON, or JSONL files and the query should remain read-only. Open Database Analyze Tools when you need a different database inspection or measurement page.
Frequently asked questions
Can I run SQL on CSV and JSON files?
Yes. Load one or more supported files, then query the generated table names with the read-only SQL syntax.
Can I join two CSV or JSON files?
Yes. Each file becomes a named table. Use INNER JOIN or LEFT JOIN with an ON condition.
Why does my CSV column show as NULL?
Empty delimited fields and missing fields become NULL. A blank header becomes a generated name such as column_1.
Are CSV and JSON files uploaded to a server?
No. The page reads files with File.text() and parses and queries them locally in the browser. The file-processing code makes no network request with the file contents.
Why is Export CSV hidden after my query?
Export controls appear when the last query returns at least one row. A query with zero rows still reports its column count and row count, and there are no rows to export.