by Audrey M. Roy Greenfeld | Tue, May 6, 2025
How to get JSON into a local SQLite database fast.
Last year I downloaded and read the sqlite-utils docs as an .epub file to read like a book on the Eurostar from Paris to London. It was then that I discovered the amazing command-line side of sqlite-utils. It's powerful and I'm only scratching the surface of what can be done with it.
To start, I had Grok 3 generate a list of Filipino languages in JSON. I saved it as langs.json. I had it include an integer primary key. (I also tried Claude 3.7, Deepseek, Gemini 2.5 Pro, ChatGPT 4.5. Grok 3 gave me the longest list, though quite incorrect.)
I like to use the sqlite-utils CLI tool as a uvx tool, giving it its own isolated environment. This one-liner turns the JSON into a SQLite database:
uvx sqlite-utils insert langs.db langs langs.json --pk=id
langs.db
is the database filenamelangs
is the table name I want for the datalangs.json
is the file containing the data to import, which I created earlier.uvx datasette langs.db
Then go to http://127.0.0.1:8001/langs/langs and you should see all the entries in a nicely-browsable table.