Skip to main content

Filter JSON and JSON Lines data with Python syntax.

Project description

jello

Filter JSON and JSON Lines data with Python syntax

jello is similar to jq in that it processes JSON and JSON Lines data except jello uses standard python dict and list syntax.

JSON or JSON Lines can be piped into jello (JSON Lines are automatically slurped into a list of dictionaries) and are available as the variable _. Assign the output the the variable r to print as JSON or simple lines.

Install

pip3 install --upgrade jello

Usage

<JSON Data> | jello [OPTIONS] query

query can be most any valid python code as long as the result is assigned to r. _ is the sanitized JSON from STDIN presented as a python dict or list of dicts. For example:

$ cat data.json | jello 'r = _["key"]'

The JSON output is pretty printed by default, but can be compact printed by using the -c option.

Examples:

lambda functions and math

$ echo '{"t1":-30, "t2":-20, "t3":-10, "t4":0}' | jello '\
keys = _.keys()
vals = _.values()
cel = list(map(lambda x: (float(5)/9)*(x-32), vals))
r = dict(zip(keys, cel))'

{
  "t1": -34.44444444444444,
  "t2": -28.88888888888889,
  "t3": -23.333333333333336,
  "t4": -17.77777777777778
}

$ jc -a | jello 'r = len([entry for entry in _["parsers"] if "darwin" in entry["compatible"]])'

32

for loops

Output as JSON array

jc -a | jello '\
r = []
for entry in _["parsers"]:
  if "darwin" in entry["compatible"]:
    r.append(entry["name"])'

[
  "airport",
  "airport_s",
  "arp",
  "crontab",
  "crontab_u",
  ...
]

Output as bash array

jc -a | jello '\
r = []
for entry in _["parsers"]:
  if "darwin" in entry["compatible"]:
    r.append(entry["name"])
r = "\n".join(r)'

airport
airport_s
arp
crontab
crontab_u
...

List and Dictionary Comprehension

Output as JSON arrauy

$ jc -a | jello 'r = [entry["name"] for entry in _["parsers"] if "darwin" in entry["compatible"]]'

[
  "airport",
  "airport_s",
  "arp",
  "crontab",
  "crontab_u",
  ...
]

Output as bash array

$ jc -a | jello 'r = "\n".join([entry["name"] for entry in _["parsers"] if "darwin" in entry["compatible"]])'

airport
airport_s
arp
crontab
crontab_u
...

Environment Variables

$ echo '{"login_name": "joeuser"}' | jello '\
r = True if os.getenv("LOGNAME") == _["login_name"] else False'

True

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

jello-0.2.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

jello-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file jello-0.2.0.tar.gz.

File metadata

  • Download URL: jello-0.2.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.6

File hashes

Hashes for jello-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d992d6f5200cf6173c5ba3eb984e665d9e45c85b9531647e1fcd7639b7fe6e85
MD5 5cbafcd834b9ef7b7b7d76defde0534e
BLAKE2b-256 caeb1a37a52c9838b0f876d0af2f6e373453b30e0bfad77c210d8815074e2461

See more details on using hashes here.

File details

Details for the file jello-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jello-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.6

File hashes

Hashes for jello-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a373210ab0908be582ad69533dfab3d0339deec888b383af38eb1bc94a88158b
MD5 79892fd272ae6ad21b8f4807a2f0f1e3
BLAKE2b-256 bb333a8aa42e3a3633639becbcb35736317f4009ec3d836744a30386027d774d

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