Convert JSON arrays to SQL INSERT statements from the command line
Project description
json2sql
Convert JSON arrays to SQL INSERT statements without manual work.
Install
pip install jsontosqlquery
Usage
# From file
jsontosqlquery users.json --table users
# From stdin
cat data.json | jsontosqlquery --table orders
# Write to file + include CREATE TABLE
jsontosqlquery data.json --table products --output products.sql --create-table
# Multi-row batches (faster for large datasets)
jsontosqlquery big.json --table events --batch 500
# MySQL dialect
jsontosqlquery data.json --table items --dialect mysql
Input (users.json)
[
{"id": 1, "name": "Alice", "active": true},
{"id": 2, "name": "Bob", "active": false}
]
Output
INSERT INTO "users" ("id", "name", "active") VALUES
(1, 'Alice', TRUE);
INSERT INTO "users" ("id", "name", "active") VALUES
(2, 'Bob', FALSE);
Options
| Flag | Description |
|---|---|
--table, -t |
Target table name (required) |
--output, -o |
Write SQL to a file (default: stdout) |
--dialect |
standard (default) / postgres / mysql |
--create-table |
Prepend CREATE TABLE IF NOT EXISTS |
--batch N |
Emit multi-row INSERT batches of N rows |
Type inference
| JSON type | SQL type |
|---|---|
null |
NULL |
true / false |
BOOLEAN |
| Integer | INTEGER |
| Float | REAL |
| String | VARCHAR(255) |
| Array / Object | TEXT (serialised as JSON) |
Missing keys in mixed-key records become NULL.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsontosqlquery-1.0.1.tar.gz
(8.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsontosqlquery-1.0.1.tar.gz.
File metadata
- Download URL: jsontosqlquery-1.0.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09c98023f6f1c7aac348e4aeaa4851bc87366635a17214f7b19b316d067d755f
|
|
| MD5 |
a6ac4b5b9b3d7c6c29a65c0abdf57656
|
|
| BLAKE2b-256 |
ff0982175f33d3e095eade523477c3da8facfe0ba8545fd6fb8044be32ce05fd
|
File details
Details for the file jsontosqlquery-1.0.1-py3-none-any.whl.
File metadata
- Download URL: jsontosqlquery-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f50f5907bab45843c5db75335dbbc3fcf160921771785defbb38fddf5f447b4
|
|
| MD5 |
59063996b089e191713e3f793d6d606e
|
|
| BLAKE2b-256 |
60ab0b3ab53ea9e5e6c9c9e46bb9d900c6a13ea448c9fd3f9c8cd443169568c3
|