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.0.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.0.tar.gz.
File metadata
- Download URL: jsontosqlquery-1.0.0.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 |
625fc8bbab277222d8322dc95b803c66ef13082cda737fea352420ca024ffa47
|
|
| MD5 |
2e60038362aa4844d050469055f56e7c
|
|
| BLAKE2b-256 |
bf6335f9f4b71eb4fbe0b20502aae422b954b65999db3563db14eeddc93758c4
|
File details
Details for the file jsontosqlquery-1.0.0-py3-none-any.whl.
File metadata
- Download URL: jsontosqlquery-1.0.0-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 |
cd41d91f25ff45977ce5d491b8696244329b9f3dc08d0fa8f3ca937f50064688
|
|
| MD5 |
64f8bbebb8c8b58c7694d7fa61d6a438
|
|
| BLAKE2b-256 |
535ec083110c9ef428f9ec41a6b5bb0375d3ae162608653e854a3bf2712ac9ae
|