Skip to main content

jq for pythonista

Project description

jq is too difficult

jq is too difficult, at least for me.

For example, extracting key-name when use is true only, from below JSON data.

{
  "apps": {
    "foo": {
      "use": true
    },
    "bar": {
      "use": true
    },
    "boo": {
      "use": true
    },
    "bee": {
      "use": false
    }
  }
}

What is jq’s answer? (taking over 30 minutes, my past challenges).

$ cat data.json | jq '.apps | . as $$o | keys | map(select($$o[.].use))'
[
  "bar",
  "boo",
  "foo"
]

If you have python’s knowledge, this is tiny oneliner, isn’t it?

$ cat data.json | jqfpy '[k for k, opts in get("apps").items() if opts["use"]]'
[
  "foo",
  "bar",
  "boo"
]

(get() is special function, like a json.load(sys.stdin).get.)

install

pip install jqfpy

how to use

describe syntax

todo.

tutorial

this is jqfpy version of jq’s Tutorial.

alias jsonDATA="curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5'"
# jq.
jsonDATA | jq '.'
# jqfpy.
jsonDATA | jqfpy 'get()'
# jq.
jsonDATA | jq '.[0]'
# jqfpy.
jsonDATA | jqfpy 'get()[0]'
# jq.
jsonDATA | jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
# jqfpy.
jsonDATA | jqfpy 'd = get()[0]; {"message": get("commit/message", d), "name": get("commit/committer/name", d)}'
# or
jsonDATA | jqfpy '{"message": get("0/commit/message"), "name": get("0/commit/committer/name")}'
# jq.
jsonDATA | jq '.[] | {message: .commit.message, name: .commit.committer.name}'
# jqfpy.
jsonDATA | jqfpy --squash 'L = get(); [{"message": get("commit/message", d), "name": get("commit/committer/name", d)} for d in L]'
# jq.
jsonDATA | jq '[.[] | {message: .commit.message, name: .commit.committer.name, parents: [.parents[].html_url]}]'
# jqfpy.
jsonDATA | 'L = get(); [{"message": get("commit/message", d), "name": get("commit/committer/name", d), "parents": [p["html_url"] for p in d["parents"]]} for d in L]'

0.3.2

  • the future is dropped that showing help when calling with no arguments

0.3.0

  • experimental yaml format support

0.2.0

  • correct behaviours of –slurp and –unbuffered

  • support accessing data by json pointer like format

  • compact output support

  • multiple files support

  • exec code only once

0.1.0

  • adding some options

  • nocode is same as jq . (js == jq .)

  • showing pycode when error is raised

0.0.1

  • first release

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

jqfpy-0.3.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

jqfpy-0.3.2-py2.py3-none-any.whl (9.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jqfpy-0.3.2.tar.gz.

File metadata

  • Download URL: jqfpy-0.3.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jqfpy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6f418d24db6c2644243cb58247775f3564a94229721566a0ebb39825b8179c66
MD5 2094378355dacf71e9f57245e8aea824
BLAKE2b-256 e1bbc00490869369bd61b0f9690a7e3646cfc0e700f7777b4b530db71797beb3

See more details on using hashes here.

File details

Details for the file jqfpy-0.3.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jqfpy-0.3.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fc1ef98ae644f3375f812c3ef83e52b4b8a688bafb2dd379d8e6314b13881c36
MD5 b7d0a13892bde47de25f369ef15b7bb0
BLAKE2b-256 b22f80a9ae87dee9d4ee3da0ecae178c329e2c8c2cc0f8e1d3627a3a47c4adde

See more details on using hashes here.

Supported by

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