{"id":45181163,"url":"https://github.com/Florents-Tselai/pgJQ","last_synced_at":"2026-03-05T08:01:15.413Z","repository":{"id":193840197,"uuid":"689595340","full_name":"Florents-Tselai/pgJQ","owner":"Florents-Tselai","description":"jq extension for Postgres","archived":false,"fork":false,"pushed_at":"2024-12-09T15:55:37.000Z","size":208,"stargazers_count":196,"open_issues_count":4,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-24T17:03:59.099Z","etag":null,"topics":["dsl","jq","json","postgres"],"latest_commit_sha":null,"homepage":"https://tselai.com/pgjq-dsl-database.html","language":"C","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/Florents-Tselai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Florents-Tselai"]}},"created_at":"2023-09-10T10:14:05.000Z","updated_at":"2025-05-13T05:58:15.000Z","dependencies_parsed_at":"2023-09-10T11:34:04.276Z","dependency_job_id":"63a6b720-61d3-4c0e-8cae-0872690b9055","html_url":"https://github.com/Florents-Tselai/pgJQ","commit_stats":{"total_commits":2,"total_committers":2,"mean_commits":1.0,"dds":0.5,"last_synced_commit":"95bb3bbe4d4deff5baa9ee6c0c76674f818bf4e8"},"previous_names":["florents-tselai/pgjq"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Florents-Tselai/pgJQ","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FpgJQ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FpgJQ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FpgJQ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FpgJQ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Florents-Tselai","download_url":"https://codeload.github.com/Florents-Tselai/pgJQ/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FpgJQ/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30115662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T03:40:26.266Z","status":"ssl_error","status_checked_at":"2026-03-05T03:39:15.902Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dsl","jq","json","postgres"],"created_at":"2026-02-20T10:00:30.837Z","updated_at":"2026-03-05T08:01:15.402Z","avatar_url":"https://github.com/Florents-Tselai.png","language":"C","funding_links":["https://github.com/sponsors/Florents-Tselai","https://github.com/sponsors/Florents-Tselai/","https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026link=https://github.com/sponsors/Florents-Tselai/"],"categories":["C"],"sub_categories":[],"readme":"# pgJQ: Use `jq` in Postgres\n\n\u003ca href=\"https://hub.docker.com/repository/docker/florents/pgjq\"\u003e\u003cimg alt=\"Docker Pulls\" src=\"https://img.shields.io/docker/pulls/florents/pgjq\"\u003e\u003c/a\u003e\n\u003cimg alt=\"GitHub Repo stars\" src=\"https://img.shields.io/github/stars/Florents-Tselai/pgJQ\"\u003e\n\u003ca href=\"https://www.linkedin.com/in/florentstselai/\"\u003e\u003cimg src=\"https://img.shields.io/badge/LinkedIn-0077B5?logo=linkedin\u0026logoColor=white\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/sponsors/Florents-Tselai/\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026link=https://github.com/sponsors/Florents-Tselai/\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT license\"\u003e\u003cimg src=\"https://img.shields.io/badge/MIT license-blue.svg\"\u003e\u003c/a\u003e\n\n*Note*: If you like this idea check out: [liteJQ: jq extension for SQLite](https://github.com/Florents-Tselai/liteJQ)\n\nThe **pgJQ**  extension embeds the standard jq compiler and brings the much loved [jq](https://github.com/jqlang/jq) lang to Postgres.\n\nIt adds a `jqprog` data type to express `jq` programs \nand a `jq(jsonb, jqprog)` function to execute them on `jsonb` objects.\nIt works seamlessly with standard `jsonb` functions, operators, and `jsonpath`.\n\n```sql\nSELECT jq('[{\"bar\": \"baz\", \"balance\": 7.77, \"active\":false}]'::jsonb, '.[0].bar');\n```\n\n```\n  jq   \n-------\n \"baz\"\n(1 row)\n```\n\n![til](./pgjq-demo.gif)\n\n\n\n## Usage\n\n### Filters\n\nYou can run basic filters:\n\n```sql\nSELECT jq('[{\"bar\": \"baz\", \"balance\": 7.77, \"active\":false}]'::jsonb, '.[0].bar');\n```\n\n```\n  jq   \n-------\n \"baz\"\n(1 row)\n```\n\n### `jsonb` `@@` `jqprog`\n\nIf you're a syntactic sugar addict, you can use the `@@` operator to achieve the same.\nIt's better be explicit with the `::jqprog` when using operators.\n\n```sql\nSELECT '[{\"bar\": \"baz\", \"balance\": 7.77, \"active\":false}]' @@ '.[0].bar'::jqprog;\n```\n\n```\n  jq   \n-------\n \"baz\"\n(1 row)\n```\n\n### Complex Programs\n\nYou can run more complex `jq` programs too:\n\n```sql\nSELECT jq('[true,false,[5,true,[true,[false]],false]]',\n          '(..|select(type==\"boolean\")) |= if . then 1 else 0 end');\n```\n```\n             jq              \n-----------------------------\n [1, 0, [5, 1, [1, [0]], 0]]\n(1 row)\n```\n\n```sql\nSELECT jq('[1,5,3,0,7]' , '(.[] | select(. \u003e= 2)) |= empty');\n```\n```\n   jq   \n--------\n [1, 0]\n(1 row)\n```\n\n### Passing Arguments to `jqprog`\n\nIf you want to pass dynamic arguments to `jqprog`,\nyou can pass them as a `jsonb` object\nand refer to them as `$var`.\n\n```sql\nselect jq('{\n  \"runner\": 1,\n  \"message\": \"jobStatus\",\n  \"jobs\": [\n    {\n      \"id\": 9,\n      \"is_successfull\": true\n    },\n    {\n      \"id\": 100,\n      \"is_successfull\": false,\n      \"metdata\": {\n        \"environ\": \"prod\"\n      }\n    }\n  ]\n}'::jsonb, '.jobs[] | select(.is_successfull == $is_success and .id == 100) | .', '{\"is_success\": false, \"id\": 100}');\n```\n```\n                                  jq                                  \n----------------------------------------------------------------------\n {\"id\": 100, \"metdata\": {\"environ\": \"prod\"}, \"is_successfull\": false}\n(1 row)\n```\n\n### `jq` and `jsonpath`\n\nYou can even chain `jq` and `jsonpath` together!\n\nNote here that the later part `- '{trans}' @\u003e '{\"cust\": \"baz\"}'` is `jsonpath`, not `jq` code.\n```sql\nSELECT jq('[\n  {\n    \"cust\": \"baz\",\n    \"trans\": {\n      \"balance\": 100,\n      \"date\": \"2023-08-01\"\n    },\n    \"active\": true,\n    \"geo\": {\n      \"branch\": \"paloukia\"\n    }\n  }\n]', '(.[] | select(.active == true))') - '{trans}' @\u003e '{\"cust\": \"baz\"}';\n```\n```\n ?column? \n----------\n t\n(1 row)\n```\n\nIf you opt for using operators here, you should help the parser by adding parentheses and explicit casts.\n\n```sql\nSELECT ('[\n  {\n    \"cust\": \"baz\",\n    \"trans\": {\n      \"balance\": 100,\n      \"date\": \"2023-08-01\"\n    },\n    \"active\": true,\n    \"geo\": {\n      \"branch\": \"paloukia\"\n    }\n  }\n]' @@ '(.[] | select(.active == true))'::jqprog) - '{trans}' @\u003e '{\"cust\": \"baz\"}';\n```\n\nIt is strongly recommended to be explicit \nwith type casts and ordering when using overloaded operators,\nespecially when you're working a lot with text.\nOtherwise, you'll find yourself in an obfuscated labyrinth of\n`jqprog`s, `jsonb`s,  `jsonpath`s and possibly `tsvector`s ,\nimpossible to escape from.\n\n### Working with Files\n\nIf you have superuser privileges in Postgres you can use the `pg_read_file` \nto run your queries on JSON files.\n\n```sql\nSELECT jq(pg_read_file('/path/to/f.json', '.[]'))\n```\n\nYou can see more examples in the [test cases](test/sql/basic.sql) \nor try reproducing the [`jq` manual](https://jqlang.github.io/jq/manual/) .\n\n## Installation\n\n```sh\ngit clone https://github.com/Florents-Tselai/pgJQ.git\ncd pgJQ\nmake install # set PG_CONFIG=/path/to/bin/pg_config if necessary.\nmake installcheck\n```\n\nIn a Postgres session run\n\n```sql\nCREATE EXTENSION pgjq\n```\n\n## How it Works\n\npgJQ does not re-implement the `jq` lang in Postgres.\nIt instead embeds the standard `jq` compiler and uses it to parse `jq` programs supplied in SQL queries.\nThese programs are fed with `jsonb` objects as input.\n\n## Issues\n\n`jq` has evolved from *just a cli tool* to a full-fledged DSL,\nbut it still remains a 20-80 tool.\n\n**pgJQ** has been TDDed against those 20% of the cases.\nIf you come across regressions between vanilla `jq` and pgJQ,\nespecially around piped filters or complex functions,\nplease do add an issue, along with a test case!\n\nKeeping in mind, though, that there's probably not much point reproducing the whole \nDSL in an RDBMS context.\n\nSome known issues are:\n* Only string, bool and numeric arguments can be passed to `jqprog`.\n* Currently, `jq` programs including pipes, like `.[] | .name` are buggy and unpredictable.\n* Modules are not supported, but they could be theoretically supported, given that Postgres is fairly open to dynamic loading.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlorents-Tselai%2FpgJQ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFlorents-Tselai%2FpgJQ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlorents-Tselai%2FpgJQ/lists"}