https://github.com/peter554/jsonsqlquery
Query JSON with SQL
https://github.com/peter554/jsonsqlquery
Last synced: about 1 month ago
JSON representation
Query JSON with SQL
- Host: GitHub
- URL: https://github.com/peter554/jsonsqlquery
- Owner: Peter554
- License: mit
- Created: 2023-03-04T18:50:20.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T09:58:07.000Z (over 3 years ago)
- Last Synced: 2025-10-27T10:35:46.285Z (9 months ago)
- Language: Python
- Size: 20.5 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonsqlquery
[](https://github.com/Peter554/jsonsqlquery/actions/workflows/ci.yml)
Query JSON using SQL.
```
pip install jsonsqlquery
```
## Examples
```
# students.jsonl
{"name": "Alvin", "age": 25, "major": "Literature"}
{"name": "Kathy", "age": 31, "major": "Literature"}
{"name": "Pauline", "age": 11, "major": "Mathematics"}
{"name": "Nora", "age": 27, "major": "Mathematics"}
{"name": "Martin", "age": 54, "major": "Geology"}
```
Inline SQL query:
```
cat students.jsonl | jsonsqlquery --query 'select name, age from data where age > 30'
```
SQL query from a file:
```
cat students.jsonl | jsonsqlquery --query-file query.sql
```
Create a SQLite database:
```
cat students.jsonl | jsonsqlquery --create-db students.db
```
Python API:
```py
import jsonsqlquery
students = [...]
older_students = jsonsqlquery.query(students, "select name, age from data where age > 30")
```
## Caveats
* Data is cast to SQLite data types.
* Data is assumed to fit in memory.