JSON analysis
How to Analyze JSON Files Locally with SQL
Load JSON or NDJSON into a local DuckDB table, then use SQL to inspect records, filter fields, and work with nested values.
On This Page
Supported JSON shapes
SQL for Files is a good fit for JSON arrays and newline-delimited JSON where each object represents one row. That makes logs, API exports, product catalogs, and event files easier to inspect with SQL.
- JSON array files such as [{...}, {...}].
- NDJSON files where each line is one JSON object.
- Nested arrays or structs that you can inspect and flatten with SQL patterns.
Add JSON data
- Open the editor and add your JSON or NDJSON file.
- Review the created table in the Database sidebar.
- Preview the first rows to confirm field names and inferred types.
- Run focused queries before writing larger transformations.
Query top-level fields
When your JSON records have consistent top-level fields, you can query them like columns in a regular table.
SELECT event_type, user_id, created_at
FROM events
WHERE event_type = 'purchase'
ORDER BY created_at DESC
LIMIT 100;Summarize JSON records
Aggregation works well for event counts, API status codes, product categories, and user activity summaries.
SELECT
event_type,
COUNT(*) AS events
FROM events
GROUP BY event_type
ORDER BY events DESC;Work with nested JSON
Nested JSON often needs one extra step: unnest lists into rows or expand structs into columns. DuckDB includes SQL features for these patterns, and the Learn SQL track includes lessons on UNNEST for nested data.
SELECT
order_id,
item.name AS item_name,
item.quantity
FROM orders,
UNNEST(items) AS item;Analyze JSON without uploading it
JSON exports can contain logs, customer IDs, analytics events, or sensitive operational data. SQL for Files keeps JSON processing in the browser, so you can inspect files without sending them to a hosted database or converter.
Continue in the editor
Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.
Open editorRelated guides
Practical SQL Examples for CSV, JSON, and Parquet Files
A compact collection of SQL patterns you can adapt for local file analysis in SQL for Files.
How to Query Parquet Files in the Browser
Use browser-based DuckDB to inspect Parquet files, run fast analytical queries, and export compact results without a local database install.
Private Local Data Analysis in the Browser
Understand the local processing model behind SQL for Files and how to work safely with sensitive CSV, JSON, and Parquet files.