Skip to main content

jsh: JSON-RPC standards for the shell

jsh refers to both:

  • JSH: a standard protocol for "shell scripts" to be able to talk to eachother in a manner similar to JSON-RPC, along with a jshlib.py single-file python library reference implementation.
  • jsh: a cmdline tool for converting standard shell-like arguments into json.

The JSH spec is almost identical to the JSON-RPC 2.0 specification. It is a specification for cmdline programs to take a jsonrpc compatible json blob via the argument --jsh-request argument. i.e. if ls supported JSH the following might have similar functionality:

ls --all /foo/bar

REQUEST='{
  "jsonrpc":"2.0",
  "method":"ls",
  "params":{"all":true, "path": "/foo/bar"}
}'
ls --jsh-request "$REQUEST"

ls --jsh-request $(jsh m=ls --all=true --path='"/foo/bar"')

In addition to this, JSH requires the following when the --jsh-request is passed:

  • MUST output valid json on stdout UNLESS a documented application defined flag in params or method specifies otherwise (i.e. Method vs MethodBinary)
    • If outputing multiple 'results' (i.e. list of files, results of search, etc), MUST output them as separate records separated by newlines \n
    • These can be iteratively injsested by jshlib.load_jsh
  • SHOULD output structured logs to stderr, one json record per line, in the form (other keys are allowed)
{"lvl":"ERROR", "msg":"this is a message"}

JSH was explicitly developed for use in build systems, which often need to combine outputs from multiple stages using many different programming languages. However, it's purpose is broader reaching:

  • Elminiate the error-prone parsing of outputs, using JSON instead.
    • Standard composability of developer tooling, both at the OS level and higher.
    • Still allowing for fast development and prototyping in any language.
  • Enable the user of json query tools (like jq) to munge and redirect data, as opposed to text-based tools like awk or sed.
  • Allow for shell scripts to quickly be "hosted".
    • Trivial to make them work via web requests, allowing faster and cleaner sysadmin interfaces.

Usage and API

pip install jshlib

jsh cmdline tool

Comes with cmdline tool jsh which can:

  • Create json-rpc request for use with JSH compliant commands.
  • (future) format json to be more human readable
  • (future) create well-formatted tables for certain formats of output

jshlib python library

The following functions and types are essential:

  • parse_jsh_argv: parses the argv cmdline arguments for JSH compliance
  • Request and Error objects, which represent the appropriate JSON-RPC objects.
  • dump_stdout and dump_stderr for dumping python objects (dict, list, int, etc) to the respective output.
  • load_json_iter will continuously load json objects from a stream (i.e. stdin, stdout, file socket, etc). This allows for semi-performantly chaining jsh tools, assuming that each one outputs its "records" as they becomes available.

It is planned to support more languages ASAP.

License

The source code is Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Metadata

Release files for jshlib 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jshlib 0.1.0
File Size Uploaded
jshlib-0.1.0.tar.gz 7.9 kB Details

Release files / jshlib-0.1.0.tar.gz

Download URL jshlib-0.1.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0a77d6ea6e33e89dfa6665798ebf658aa6bdeaf313c89f683e7cbc6e1dcb8cef
BLAKE2b-256 checksum
How to use checksums
97b124231a0c459b4c7aedccb5cf4c3f83ce433b12b27f1bdc47484ba73266a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page