KSON: JSON with SQL and Networking
Of course it's a good idea: why would you ask?
KSON is a superset of JSON with the following features:
- Remote document references (so you can embed a JSON, KSON, or CSV file available at a public URL or file address)
- Embedded SQL: Write queries against other objects in your JSON file (including references and deeply nested objects) with the full power of SQLite and have the queries evaluate to JSON
- Use comments (
/* ... */) and global named references ("foo": "bar" as myRef). - Compiles to JSON: Run
kson file.kson(see installation instructions below) and boom! you have JSON.
KSON combines the portability of the top data exchange formats (JSON, CSV) with the expressiveness of the leading data querying language (SQL), and the flexibility of dynamic embedded references.
Installation
Run
python3 -m pip install -g kson
This will create a global executable kson which you can run on
.kson files to produce .json files:
kson file.kson # Sends JSON to stdout
or
kson file.kson > file.json # Pipe the output to a file
Examples
You can find examples in the examples/ directory.
- examples/gdp.kson: Demonstrates how you can query an external data source (in this case, CSV file on GitHub.)
- examples/join-gdp-and-population.kson: Fetch data from two data sources (GDP by country and population by country) and perform a join to see GDP per capita.
FAQ
How does this work?
It's pretty simple, actually: First we parse the KSON file via recursive descent. Where JSON has arrays and dictionaries, we throw in a few extra types - refs, aliases, and SQL queries.
To compile the file, we traverse the tree, making network requests, building appropriately-named SQLite tables, and performing SQL queries as we go, eventually collapsing the whole business to JSON.
Some constraints of this approach are that we make network requests in serial, and that you must define an alias before any SQL queries which use it. On the other hand, we achieve a great deal of flexibility in indexing into deeply nested remote documents: suppose a remote document has a structure like so:
{
"foo": {
"bar": {
"baz": [
1,
2,
3,
4
]
}
}
}
If we alias the document as doc, then our SQL queries can acess the contents of the array by querying
select * from "$doc$foo$bar$baz".
Is this a good idea, and where did you get it?
Haha, well, um. More appropriate adjectives might include "interesting", "tempting", and "risky".
For reasons which are best elided, I had to write an enormous number of JSON parsers in a short period of time, and then got some additional ideas about the format. It's called "KSON" because k comes after j, get it? :-)
Metadata
Release files for kson-jbrazeal 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kson-jbrazeal-0.0.1.tar.gz | 3.7 kB | Without provenance | Details for kson-jbrazeal-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kson_jbrazeal-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for kson_jbrazeal-0.0.1-py3-none-any.whl |
Total release size: 7.3 kB
Release files / kson-jbrazeal-0.0.1.tar.gz
| Download URL | kson-jbrazeal-0.0.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90244ba336579f255339b824443582ff23597ad503d666390a00a970d911d3da
|
|
BLAKE2b-256 checksum How to use checksums |
b9b193f4a6aec833d4ffedc1380112f7f59400c27c5b086edff1dbfda65e9060
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.0
|
Release files / kson_jbrazeal-0.0.1-py3-none-any.whl
| Download URL | kson_jbrazeal-0.0.1-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c314b24bd66f4f8b08bc97e7d86c126fed7727ef960b520dd573559a8cb44599
|
|
BLAKE2b-256 checksum How to use checksums |
75e3255c49f959b957c2fd94303a03009269cc9f361ebbaf8d06652ddfc0ddc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.0
|
Security for kson-jbrazeal 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.