Skip to main content

KSON is JSON with embedded SQL and networking

Project description

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.

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? :-)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kson-jbrazeal-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kson_jbrazeal-0.0.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file kson-jbrazeal-0.0.1.tar.gz.

File metadata

  • Download URL: kson-jbrazeal-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for kson-jbrazeal-0.0.1.tar.gz
Algorithm Hash digest
SHA256 90244ba336579f255339b824443582ff23597ad503d666390a00a970d911d3da
MD5 609ddec5bda982acc64287c4f5038da3
BLAKE2b-256 b9b193f4a6aec833d4ffedc1380112f7f59400c27c5b086edff1dbfda65e9060

See more details on using hashes here.

File details

Details for the file kson_jbrazeal-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: kson_jbrazeal-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for kson_jbrazeal-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c314b24bd66f4f8b08bc97e7d86c126fed7727ef960b520dd573559a8cb44599
MD5 0dff38c16fa9d795af698bed10b64681
BLAKE2b-256 75e3255c49f959b957c2fd94303a03009269cc9f361ebbaf8d06652ddfc0ddc6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page