SQLite to JSON: Tables and Query Results

One JSON document per table, or one object per row, with the types kept: numbers stay numbers, NULL stays null, and text stays text.

Download DBToFile — free trial

Version 3.1.2 · Windows, Linux, macOS · 30-day free trial, then $75 one-time · runs fully offline

DBToFile: SQLite to JSON target - document shape, indentation and NULL handling

How to Export SQLite to JSON, Step by Step

Step 1: Open the SQLite database

A SQLite database is a file: choose the .db (or .sqlite) and the tables appear. There is no host, port or account - the only concern is the file being locked by another process.

Step 1 screenshot

Step 2: Choose the table or the query

One table, every table in the file, or a SELECT pasted straight in - the column list comes from what you pick and stays editable.

Step 2 screenshot

Step 3: Set the JSON shape

Delimiter, quoting, header row, NULL marker, encoding and the file name - set once and saved with the task. Dynamic file name covers the dated-file case the old export-...-with-current-date posts described.

Step 3 screenshot

Step 4: Run and check the file

The task window reports the row count at the end; open the file and check the first and last row before anything else consumes it.

Step 4 screenshot

Key Features

A SQLite file is a single file with dynamic types, so the export is really a set of decisions about what each column means. DBToFile keeps those decisions together with the query:

  • Table, query, or multiple tables at once - a batch run writes one file per table, named after it.
  • Column list and order are part of the task, so the output does not drift when the schema grows.
  • Affinity is honoured: INTEGER stays a number, TEXT stays text, and a 19-digit id can be kept as text.
  • NULL keeps a marker, so empty and NULL do not silently become the same value.
  • Saved and scheduled: the same task runs from Task Scheduler, cron or launchd.
  • Local: the .db file and its output never leave the machine.

What a SQLite column becomes in the JSON

SQLite stores what you put in it, so a JSON export is decided by the column contents rather than by a declared type - these are the pairs that matter:

In SQLiteIn the JSON
INTEGERa JSON number - beyond 2^53 a JavaScript parser rounds it
REAL, NUMERICa JSON number; REAL is already a float
TEXTa JSON string, escaped
NULLthe JSON literal null - the one format where NULL survives
Date / timea string, because JSON has no date type; an epoch INTEGER stays a number
BOOLEAN0 / 1 as a number, unless the mapping writes true/false
BLOBnot text - export HEX(col) or it cannot be valid JSON

One array, one object per line, or json_group_array() in SQL?

SQLite has JSON functions (json_group_array, json_object) and they are the right tool for shaping a report inside a query. What they do not give you is a file: the aggregate is built in memory and the whole thing has to be fetched in one piece.

Two shapes are what consumers actually ask for: one array of objects (web APIs) and one object per line - JSONL/NDJSON - which appends and streams. The choice is a setting here, not a different tool.

SQLite to JSON — Quick Facts

Shape
array of objects, or one object per row (JSONL)
Numbers
INTEGER beyond 2^53 is at risk in float parsers
Dates
strings - JSON has no date type
NULL
the literal null
Source
a SQLite .db file
SQL-side alternative
json_object / json_group_array, built in memory

Common pitfalls when exporting SQLite to JSON

  • A column already holding JSON text is exported as a string, so the consumer sees double-encoded JSON.
  • 19-digit ids change value when a JavaScript parser reads them as numbers.
  • TEXT dates stay strings; a consumer that expects epoch integers needs the query to cast them.
  • One huge array cannot be streamed - a reader has to parse the whole file before the first row.

Which searches land here

This page exports SQLite → JSON. The neighbouring searches below mean a different direction, a different format or a different target engine:

What you searchedMeaningPage
sqlite to json, sqlite export to json, sqlite to json converter, sqlite to json onlineread the .db file, write a JSON file - no upload step, the trial is a desktop buildthis page
json to sqlitethe reverseJson To SQLite
sqlite to csv, sqlite to excel, sqlite to tsv, sqlite to txt, sqlite to xml, sqlite to sql, sqlite to htmla different output format from the same .db fileCSV / Excel / TSV / TXT / XML / SQL / HTML
sqlite to mysql, sqlite to postgres, sqlite to sql server, sqlite to oracleanother database engine as the target - a data transfer between engines, not a fileMySQL / PostgreSQL / SQL Server / Oracle
sqlite viewer export to json, sqlite editor export to jsonexporting from a viewer or an IDE - same rows, and the file still has to be written somewherethis page (GUI + CLI)

Two things decide a SQLite export before any option: whether the column holds an ISO text date or an epoch integer, and whether an id is longer than a spreadsheet can hold as a number.

Verify three things before you hand the file over

  • Row count: compare SELECT COUNT(*) with the records the task reports - a short count means a rejected row.
  • First and last row: check the header and the very last field, where quoting and newline problems show up first.
  • Types in the file: a 19-digit id should still be all digits, and a NULL should not have become 0.

Frequently Asked Questions

How do I export SQLite to JSON?
Open the .db, choose the table or query, pick the shape (array or one object per line), then write the file.
Array or JSONL?
An array is what an API expects; one object per line appends and streams, which suits logs and big tables.
Are the types preserved?
Numbers and nulls yes; dates become strings because JSON has no date type.
Is SQLite's JSON support involved?
Only if you want to shape the document in SQL. The export writes JSON from the rows either way.
Can I export only some columns?
Yes - the column list comes from the query you write.

Download Withdata DBToFile Now

Start exporting SQLite to JSON in seconds - free trial for all platforms.

$75 one-time · volume discounts to $55 · 30-day money-back · pricing & licence terms

Download Free Trial