{"id":14068732,"url":"https://github.com/ropensci/jqr","last_synced_at":"2025-10-21T20:55:59.837Z","repository":{"id":28065582,"uuid":"31562506","full_name":"ropensci/jqr","owner":"ropensci","description":"R interface to jq ","archived":false,"fork":false,"pushed_at":"2024-12-14T23:26:31.000Z","size":1119,"stargazers_count":144,"open_issues_count":16,"forks_count":13,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-21T20:55:44.085Z","etag":null,"topics":["jq","json","r","r-package","rstats"],"latest_commit_sha":null,"homepage":"https://docs.ropensci.org/jqr","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ropensci.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"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,"zenodo":null}},"created_at":"2015-03-02T20:51:13.000Z","updated_at":"2025-10-06T09:16:28.000Z","dependencies_parsed_at":"2023-11-20T16:30:04.612Z","dependency_job_id":"51014173-b3a7-480f-a1e1-8ad1e7e395f5","html_url":"https://github.com/ropensci/jqr","commit_stats":{"total_commits":269,"total_committers":8,"mean_commits":33.625,"dds":"0.46840148698884754","last_synced_commit":"26879ed2ffeb6df0390509d4c17cae00c777158d"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/ropensci/jqr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fjqr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fjqr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fjqr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fjqr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ropensci","download_url":"https://codeload.github.com/ropensci/jqr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fjqr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280333500,"owners_count":26312845,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["jq","json","r","r-package","rstats"],"created_at":"2024-08-13T07:06:22.512Z","updated_at":"2025-10-21T20:55:59.806Z","avatar_url":"https://github.com/ropensci.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"jqr\n=======\n\n```{r echo=FALSE}\nknitr::opts_chunk$set(\n  comment = \"#\u003e\",\n  collapse = TRUE,\n  warning = FALSE,\n  message = FALSE\n)\n```\n\n\n[![R-CMD-check](https://github.com/ropensci/jqr/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/jqr/actions?query=workflow%3AR-CMD-check)\n[![codecov](https://app.codecov.io/gh/ropensci/jqr/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/jqr)\n[![cran checks](https://cranchecks.info/badges/worst/jqr)](https://cranchecks.info/pkgs/jqr)\n[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/jqr?color=0DA6CD)](https://github.com/r-hub/cranlogs.app)\n[![cran version](https://www.r-pkg.org/badges/version/jqr)](https://cran.r-project.org/package=jqr)\n\nR interface to jq, a JSON processor http://jqlang.github.io/jq/\n\n`jqr` makes it easy to process large amounts of json without having to\nconvert from json to R, or without using regular expressions.  This\nmeans that the eventual loading into R can be quicker.\n\n - Introduction vignette at \u003chttps://cran.r-project.org/package=jqr\u003e\n\n## Quickstart Tutorial\n\nThe `jq` command line examples from the [jq tutorial](https://jqlang.github.io/jq/tutorial/) work exactly the same in R! \n\n```{r}\nlibrary(curl)\nlibrary(jqr)\ncurl('https://api.github.com/repos/ropensci/jqr/commits?per_page=5') %\u003e%\n  jq('.[] | {message: .commit.message, name: .commit.committer.name}')\n```\n\nTry running some of the [other examples](https://jqlang.github.io/jq/tutorial/).\n\n## Installation\n\nBinary packages for __OS-X__ or __Windows__ can be installed directly from CRAN:\n\n```r\ninstall.packages(\"jqr\")\n```\n\nInstallation from source on Linux or OSX requires [`libjq`](https://jqlang.github.io/jq/). On __Ubuntu 14.04 and 16.04 lower__ use [libjq-dev](https://launchpad.net/~cran/+archive/ubuntu/jq) from Launchpad:\n\n```\nsudo add-apt-repository -y ppa:cran/jq\nsudo apt-get update -q\nsudo apt-get install -y libjq-dev\n```\n\nMore __recent Debian or Ubuntu__ install [libjq-dev](https://packages.debian.org/testing/libjq-dev) directly from Universe:\n\n```\nsudo apt-get install -y libjq-dev\n```\n\nOn __Fedora__ we need [jq-devel](https://apps.fedoraproject.org/packages/jq-devel):\n\n```\nsudo yum install jq-devel\n````\n\nOn __CentOS / RHEL__ we install [jq-devel](https://apps.fedoraproject.org/packages/jq-devel) via EPEL:\n\n```\nsudo yum install epel-release\nsudo yum install jq-devel\n```\n\nOn __OS-X__ use [jq](https://github.com/Homebrew/homebrew-core/blob/master/Formula/jq.rb) from Homebrew:\n\n```\nbrew install jq\n```\n\nOn __Solaris__ we can have [libjq_dev](https://www.opencsw.org/packages/libjq_dev) from [OpenCSW](https://www.opencsw.org/):\n```\npkgadd -d http://get.opencsw.org/now\n/opt/csw/bin/pkgutil -U\n/opt/csw/bin/pkgutil -y -i libjq_dev\n```\n\n```{r}\nlibrary(jqr)\n```\n\n## Interfaces\n\n### low level\n\nThere's a low level interface in which you can execute `jq` code just as you would on the command line:\n\n```{r}\nstr \u003c- '[{\n    \"foo\": 1,\n    \"bar\": 2\n  },\n  {\n    \"foo\": 3,\n    \"bar\": 4\n  },\n  {\n    \"foo\": 5,\n    \"bar\": 6\n}]'\n```\n\n```{r}\njq(str, \".[]\")\n```\n\n```{r}\njq(str, \"[.[] | {name: .foo} | keys]\")\n```\n\nNote that we print the output to look like a valid JSON object to make it\neasier to look at. However, it's a simple character string or vector of strings.\nA trick you can do is to wrap your jq program in brackets like `[.[]]` instead\nof `.[]`, e.g.,\n\n```{r}\njq(str, \".[]\") %\u003e% unclass\n# vs.\njq(str, \"[.[]]\") %\u003e% unclass\n```\n\nCombine many jq arguments - they are internally combined with a pipe ` | `\n\n(note how these are identical)\n\n```{r}\njq(str, \".[] | {name: .foo} | keys\")\njq(str, \".[]\", \"{name: .foo}\", \"keys\")\n```\n\nAlso accepts many JSON inputs now\n\n```{r}\njq(\"[123, 456]   [77, 88, 99]\", \".[]\")\njq('{\"foo\": 77} {\"bar\": 45}', \".[]\")\njq('[{\"foo\": 77, \"stuff\": \"things\"}] [{\"bar\": 45}] [{\"n\": 5}]', \".[] | keys\")\n\n# if you have jsons in a vector\njsons \u003c- c('[{\"foo\": 77, \"stuff\": \"things\"}]', '[{\"bar\": 45}]', '[{\"n\": 5}]')\njq(paste0(jsons, collapse = \" \"), \".[]\")\n```\n\n\n### high level\n\nThe other is higher level, and uses a suite of functions to construct queries. Queries are constucted, then excuted internally with `jq()` after the last piped command.\n\nYou don't have to use pipes though. See examples below.\n\nExamples:\n\nIndex\n\n```{r}\nx \u003c- '[{\"message\": \"hello\", \"name\": \"jenn\"}, {\"message\": \"world\", \"name\": \"beth\"}]'\nx %\u003e% index()\n```\n\nSort\n\n```{r}\n'[8,3,null,6]' %\u003e% sortj\n```\n\nreverse order\n\n```{r}\n'[1,2,3,4]' %\u003e% reverse\n```\n\nShow the query to be used using `peek()`\n\n```{r}\n'[1,2,3,4]' %\u003e% reverse %\u003e% peek\n```\n\n#### get multiple outputs for array w/ \u003e 1 element\n\n```{r}\nx \u003c- '{\"user\":\"jqlang\",\"titles\":[\"JQ Primer\", \"More JQ\"]}'\njq(x, '{user, title: .titles[]}')\nx %\u003e% index()\nx %\u003e% build_object(user, title = `.titles[]`)\njq(x, '{user, title: .titles[]}') %\u003e% jsonlite::toJSON() %\u003e% jsonlite::validate()\n```\n\n#### string operations\n\njoin\n\n```{r}\n'[\"a\",\"b,c,d\",\"e\"]' %\u003e% join\n'[\"a\",\"b,c,d\",\"e\"]' %\u003e% join(`;`)\n```\n\nltrimstr\n\n```{r}\n'[\"fo\", \"foo\", \"barfoo\", \"foobar\", \"afoo\"]' %\u003e% index() %\u003e% ltrimstr(foo)\n```\n\nrtrimstr\n\n```{r}\n'[\"fo\", \"foo\", \"barfoo\", \"foobar\", \"foob\"]' %\u003e% index() %\u003e% rtrimstr(foo)\n```\n\nstartswith\n\n```{r}\n'[\"fo\", \"foo\", \"barfoo\", \"foobar\", \"barfoob\"]' %\u003e% index %\u003e% startswith(foo)\n'[\"fo\", \"foo\"] [\"barfoo\", \"foobar\", \"barfoob\"]' %\u003e% index %\u003e% startswith(foo)\n```\n\nendswith\n\n```{r}\n'[\"fo\", \"foo\", \"barfoo\", \"foobar\", \"barfoob\"]' %\u003e% index %\u003e% endswith(foo)\n```\n\ntojson, fromjson, tostring\n\n```{r}\n'[1, \"foo\", [\"foo\"]]' %\u003e% index\n'[1, \"foo\", [\"foo\"]]' %\u003e% index %\u003e% tostring\n'[1, \"foo\", [\"foo\"]]' %\u003e% index %\u003e% tojson\n'[1, \"foo\", [\"foo\"]]' %\u003e% index %\u003e% tojson %\u003e% fromjson\n```\n\ncontains\n\n```{r}\n'\"foobar\"' %\u003e% contains(\"bar\")\n```\n\nunique\n\n```{r}\n'[1,2,5,3,5,3,1,3]' %\u003e% uniquej\n```\n\n\n#### filter\n\nWith filtering via `select()` you can use various operators, like `==`, \n`\u0026\u0026`, `||`. We translate these internally for you to what `jq` wants \nto see (`==`, `and`, `or`).\n\nSimple, one condition\n\n```{r}\n'{\"foo\": 4, \"bar\": 7}' %\u003e% select(.foo == 4)\n```\n\nMore complicated. Combine more than one condition; combine each individual\nfiltering task in parentheses\n\n```{r}\nx \u003c- '{\"foo\": 4, \"bar\": 2} {\"foo\": 5, \"bar\": 4} {\"foo\": 8, \"bar\": 12}'\nx %\u003e% select((.foo \u003c 6) \u0026\u0026 (.bar \u003e 3))\nx %\u003e% select((.foo \u003c 6) || (.bar \u003e 3))\n```\n\n#### types\n\nget type information for each element\n\n```{r}\n'[0, false, [], {}, null, \"hello\"]' %\u003e% types\n'[0, false, [], {}, null, \"hello\", true, [1,2,3]]' %\u003e% types\n```\n\nselect elements by type\n\n```{r}\n'[0, false, [], {}, null, \"hello\"]' %\u003e% index() %\u003e% type(booleans)\n```\n\n#### key operations\n\nget keys\n\n```{r}\nstr \u003c- '{\"foo\": 5, \"bar\": 7}'\nstr %\u003e% keys()\n```\n\ndelete by key name\n\n```{r}\nstr %\u003e% del(bar)\n```\n\ncheck for key existence\n\n```{r}\nstr3 \u003c- '[[0,1], [\"a\",\"b\",\"c\"]]'\nstr3 %\u003e% haskey(2)\nstr3 %\u003e% haskey(1,2)\n```\n\nBuild an object, selecting variables by name, and rename\n\n```{r}\n'{\"foo\": 5, \"bar\": 7}' %\u003e% build_object(a = .foo)\n```\n\nMore complicated `build_object()`, using the included dataset `commits`\n\n```{r}\ncommits %\u003e%\n  index() %\u003e%\n  build_object(sha = .sha, name = .commit.committer.name)\n```\n\n#### Maths\n\n```{r}\n'{\"a\": 7}' %\u003e%  do(.a + 1)\n'{\"a\": [1,2], \"b\": [3,4]}' %\u003e%  do(.a + .b)\n'{\"a\": [1,2], \"b\": [3,4]}' %\u003e%  do(.a - .b)\n'{\"a\": 3}' %\u003e%  do(4 - .a)\n'[\"xml\", \"yaml\", \"json\"]' %\u003e%  do('. - [\"xml\", \"yaml\"]')\n'5' %\u003e%  do(10 / . * 3)\n```\n\ncomparisons\n\n```{r}\n'[5,4,2,7]' %\u003e% index() %\u003e% do(. \u003c 4)\n'[5,4,2,7]' %\u003e% index() %\u003e% do(. \u003e 4)\n'[5,4,2,7]' %\u003e% index() %\u003e% do(. \u003c= 4)\n'[5,4,2,7]' %\u003e% index() %\u003e% do(. \u003e= 4)\n'[5,4,2,7]' %\u003e% index() %\u003e% do(. == 4)\n'[5,4,2,7]' %\u003e% index() %\u003e% do(. != 4)\n```\n\nlength\n\n```{r}\n'[[1,2], \"string\", {\"a\":2}, null]' %\u003e% index %\u003e% lengthj\n```\n\nsqrt\n\n```{r}\n'9' %\u003e% sqrtj\n```\n\nfloor\n\n```{r}\n'3.14159' %\u003e% floorj\n```\n\nfind minimum\n\n```{r}\n'[5,4,2,7]' %\u003e% minj\n'[{\"foo\":1, \"bar\":14}, {\"foo\":2, \"bar\":3}]' %\u003e% minj\n'[{\"foo\":1, \"bar\":14}, {\"foo\":2, \"bar\":3}]' %\u003e% minj(foo)\n'[{\"foo\":1, \"bar\":14}, {\"foo\":2, \"bar\":3}]' %\u003e% minj(bar)\n```\n\nfind maximum\n\n```{r}\n'[5,4,2,7]' %\u003e% maxj\n'[{\"foo\":1, \"bar\":14}, {\"foo\":2, \"bar\":3}]' %\u003e% maxj\n'[{\"foo\":1, \"bar\":14}, {\"foo\":2, \"bar\":3}]' %\u003e% maxj(foo)\n'[{\"foo\":1, \"bar\":14}, {\"foo\":2, \"bar\":3}]' %\u003e% maxj(bar)\n```\n\n#### Combine into valid JSON\n\n`jq` sometimes creates pieces of JSON that are valid in themselves, but together are not.\n`combine()` is a way to make valid JSON.\n\nThis outputs a few pieces of JSON\n\n```{r}\n(x \u003c- commits %\u003e%\n  index() %\u003e%\n  build_object(sha = .sha, name = .commit.committer.name))\n```\n\nUse `combine()` to put them together.\n\n```{r}\ncombine(x)\n```\n\n## Meta\n\n* Please [report any issues or bugs](https://github.com/ropensci/jqr/issues).\n* License: MIT\n* Get citation information for `jqr` in R doing `citation(package = 'jqr')`\n* Please note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms.\n\n[![rofooter](https://www.ropensci.org/public_images/github_footer.png)](https://ropensci.org)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fjqr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropensci%2Fjqr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fjqr/lists"}