{"id":25437659,"url":"https://github.com/mumubebe/pq","last_synced_at":"2025-11-01T07:30:27.646Z","repository":{"id":40651770,"uuid":"487062955","full_name":"mumubebe/pq","owner":"mumubebe","description":"📎️ pq is a Python command-line JSON processor","archived":false,"fork":false,"pushed_at":"2023-10-23T16:41:44.000Z","size":79,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-24T20:26:19.769Z","etag":null,"topics":["json","json-parser","python","python-3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mumubebe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-04-29T17:48:55.000Z","updated_at":"2022-05-01T11:43:18.000Z","dependencies_parsed_at":"2023-02-08T00:32:35.839Z","dependency_job_id":"dd7f4297-22d6-4e8f-ba7e-7d735303981a","html_url":"https://github.com/mumubebe/pq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mumubebe%2Fpq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mumubebe%2Fpq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mumubebe%2Fpq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mumubebe%2Fpq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mumubebe","download_url":"https://codeload.github.com/mumubebe/pq/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239138762,"owners_count":19588243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","json-parser","python","python-3"],"created_at":"2025-02-17T09:19:06.570Z","updated_at":"2025-11-01T07:30:27.606Z","avatar_url":"https://github.com/mumubebe.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📎️ pq-json\npq is a Python command-line JSON processor - **almost** like (atleast inspired by 🐶️) [jq](https://github.com/stedolan/jq), but using Python focusing on simplicity and convenience with familiar syntax.\n\n## Install\n```\npip install pq-json\n```\n\n\nHere is a simple example for parsing JSON. Output from pq is pretty printed using [Rich](https://github.com/Textualize/rich).\n```\n$ echo '{\"text\": \"Text here\", \"header\": \"Header\", \"list\": [1,2,3]}' | pq\n{\n  \"text\": \"Text here\",\n  \"header\": \"Header\",\n  \"list\": [\n    1,\n    2,\n    3\n  ]\n}\n\n#j represents the current input object in a filter.\n$ echo '{\"text\": \"Text here\", \"header\": \"Header\", \"list\": [1,2,3]}' | pq 'j[\"list\"] | j * 4'\n4\n8\n12\n```\n\n### Filters\nThe processing is handled with filters, like in jq.\nj represents the current input object in a filter. \n```\n$ echo '{\"example\": \"data\", \"nothing\": \"interesting\"}' | pq \"j['example']\"\n\"data\"\n```\n\n```\n$ echo '{\"example\": \"data\", \"nothing\": \"interesting\"}' | pq \"j['example']\"\n\"data\"\n```\n\nAs default, None will not be passed.\n```\n$ echo '{\"example\": \"data\", \"nothing\": \"interesting\"}' | pq \"j.get('nada')\"\n\n```\n\n### List slicing\n\nJSON arrays are converted to Python list. \n```\n$ echo '[{\"name\": \"eric\", \"age\": 22}, {\"name\": \"daniel\", \"age\": 44}]' | pq \"j[0]\"\n{\n  \"name\": \"eric\",\n  \"age\": 22\n}\n```\n```\n$ echo '[{\"name\": \"eric\", \"age\": 22}, {\"name\": \"daniel\", \"age\": 44}]' | pq \"j[-1]\"\n{\n  \"name\": \"daniel\",\n  \"age\": 44\n}\n```\n\nAn array always iterates to the next filter. Here we are using the slice symbol [:] to highlight that we are working with an array. \n```\n$ echo '[{\"name\": \"eric\", \"age\": 22}, {\"name\": \"daniel\", \"age\": 44}]' | pq \"j[:]\"\n{\n  \"name\": \"eric\",\n  \"age\": 22\n}\n{\n  \"name\": \"daniel\",\n  \"age\": 44\n}\n```\n\n\n\n### Pipes\nPipes let you chain multiple filters by produce output to the filter to the right of the pipe. Under the hood a pipeline is a chain of generators. An array will for example yield multiple elements to the right. \n\ninput: \n```json\n[\"a\", \"b\", \"c\", \"d\"]\n```\n```\npq \"j[0:2] | j.upper()\"\n      |         |\n   filter1   filter2\n\nproduces the following result:\n\"A\"\n\"B\"\n\nIn this case, the expression j.upper() will be run each time.\n\nj[0] -\u003e \"a\".upper() -\u003e \"A\"\nj[1] -\u003e \"b\".upper() -\u003e \"B\"\n\nAnother example:\n\n$ echo '[1,2,3,4,5,6,7,8,9]' | pq 'j[:] | j**2+50'\n51\n54\n59\n66\n75\n86\n99\n114\n131\n```\n### Array constructs\nAbove example outputs a list of integers. It's possible to accumulate data into an array. Use the flag ```-a``` after the pipe sign, like this:\n```\n$ echo '[1,2,3,4,5]' | pq \"j[:] | -a max(j)\"\n5\n```\nHere is another example:\n```\n$ echo '[1,2,3,4,5,6,7,8,9]' | pq 'j[:] | j**2+50 | -a [j]'\n[51, 54, 59, 66, 75, 86, 99, 114, 131]\n```\n### Object constructs\n```\n$ echo '{\"name\":\"jan\", \"age\":4, \"parents\": [\"lisa\", \"dan\"]}' | pq '{\"name\": j[\"name\"], \"parents\": j[\"parents\"]}'\n{\n  \"name\": \"jan\",\n  \"parents\": [\n    \"lisa\",\n    \"dan\"\n  ]\n}\n```\n### Custom modules\n\nIt's possible to add additional modules to global scope from file or input string.\n\nWe can declare a variable for example.\n```\n$ echo '[1,2,3]' | pq --module 'two=2' 'j[1]*two'\n4\n```\n\n\n\n### Other examples\n\nWe can easily use built-in functions in Python\n```\n$ echo \"[1,2,3,4,5,6]\" | pq 'sum(j) | {\"total\": j}'\n{\n  \"total\": 21\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmumubebe%2Fpq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmumubebe%2Fpq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmumubebe%2Fpq/lists"}