{"id":13706705,"url":"https://github.com/SymbolixAU/jsonify","last_synced_at":"2025-05-05T23:31:24.914Z","repository":{"id":85450001,"uuid":"150085264","full_name":"SymbolixAU/jsonify","owner":"SymbolixAU","description":"R package to convert R objects to JSON","archived":false,"fork":false,"pushed_at":"2024-09-23T22:43:30.000Z","size":737,"stargazers_count":67,"open_issues_count":14,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T12:41:29.619Z","etag":null,"topics":["json","r","rapidjson"],"latest_commit_sha":null,"homepage":"https://symbolixau.github.io/jsonify/","language":"C++","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/SymbolixAU.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-24T10:17:37.000Z","updated_at":"2025-03-22T11:02:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"de0b0597-60ef-4b7c-bec2-ec28164a76cb","html_url":"https://github.com/SymbolixAU/jsonify","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fjsonify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fjsonify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fjsonify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymbolixAU%2Fjsonify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SymbolixAU","download_url":"https://codeload.github.com/SymbolixAU/jsonify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252593046,"owners_count":21773397,"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","r","rapidjson"],"created_at":"2024-08-02T22:01:05.967Z","updated_at":"2025-05-05T23:31:24.015Z","avatar_url":"https://github.com/SymbolixAU.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n[![R build status](https://github.com/SymbolixAU/jsonify/workflows/R-CMD-check/badge.svg)](https://github.com/SymbolixAU/jsonify/actions)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/jsonify)](https://CRAN.R-project.org/package=jsonify)\n![downloads](http://cranlogs.r-pkg.org/badges/grand-total/jsonify)\n[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/jsonify)](https://CRAN.R-project.org/package=jsonify)\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"# \",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\nlibrary(jsonify)\n```\n\n# jsonify\n\nConverts between R objects and JSON. \n\n```{r}\njs \u003c- '[{\"x\":1,\"y\":\"a\"},{\"x\":2,\"y\":\"b\"}]'\n( df \u003c- from_json( js ) )\n( to_json( df ) )\n\n```\n\n\n###  There are already JSON converters, why did you build this one?\n\nBecause I wanted it available at the source ( C++ ) level for integrating into other packages.\n\n### What do you mean by \"available at the source\" ?\n\nI want to be able to call the C++ code from another package, without going to \u0026 from R. Therefore, the C++ code is implemented in headers, so you can \"link to\" it in your own package. \n\nFor example, the `LinkingTo` section in **DESCRIPTION** will look something like\n\n```yaml\nLinkingTo: \n    Rcpp,\n    rapidjsonr (\u003e= 1.2.0),\n    jsonify\n```\nAnd in a c++ source file you can `#include` the header and use the available functions\n\n```c++\n#include \"jsonify/jsonify.hpp\"\n\nRcpp::StringVector my_json( Rcpp::DataFrame df ) {\n  return jsonify::api::to_json( df );\n}\n```\n\nYou can see an example of this in my `{geojsonsf}` package\n\n- [Description](https://github.com/SymbolixAU/geojsonsf/blob/master/DESCRIPTION#L17)\n- [#include](https://github.com/SymbolixAU/geojsonsf/blob/master/inst/include/geojsonsf/geojson/api/sf_api.hpp#L4)\n\n### Can I call it from R if I want to?\n\nYes. Just like the examples in this readme use `to_json()`\n\n```{r}\ndf \u003c- data.frame(\n  id = 1:3\n  , val = letters[1:3]\n  )\njsonify::to_json( df )\n```\n\n### Is it fast?\n\nyeah it's pretty good. \n\n```{r, eval = FALSE}\n\nlibrary(microbenchmark)\nlibrary(jsonlite)\n\nn \u003c- 1e6\ndf \u003c- data.frame(\n  id = 1:n\n  , value = sample(letters, size = n, replace = T)\n  , val2 = rnorm(n = n)\n  , log = sample(c(T,F), size = n, replace = T)\n  , stringsAsFactors = FALSE\n)\n\nmicrobenchmark(\n  jsonlite = {\n    jlt \u003c- jsonlite::toJSON( df )\n  },\n  jsonify = {\n    jfy \u003c- jsonify::to_json( df )\n  },\n  times = 3\n)\n\n# Unit: seconds\n#      expr      min       lq     mean   median       uq      max neval\n#  jsonlite 2.017081 2.063732 2.540350 2.110383 2.801984 3.493585     3\n#   jsonify 1.186239 1.202719 1.514067 1.219198 1.677981 2.136763     3\n\n\nmicrobenchmark(\n  jsonlite = {\n    df_jlt \u003c- jsonlite::fromJSON( jlt )\n  },\n  jsonify = {\n    df_jfy \u003c- jsonify::from_json( jfy )\n  },\n  times = 3\n)\n\n# Unit: seconds\n#      expr      min       lq     mean   median       uq      max neval\n#  jsonlite 5.034888 5.149688 5.229363 5.264489 5.326601 5.388713     3\n#   jsonify 4.551434 4.629683 4.678198 4.707932 4.741579 4.775227     3\n\nn \u003c- 1e4\nx \u003c- list(\n  x = rnorm(n = n)\n  , y = list(x = rnorm(n = n))\n  , z = list( list( x = rnorm(n = n)))\n  , xx = rnorm(n = n)\n  , yy = data.frame(\n      id = 1:n\n      , value = sample(letters, size = n, replace = T)\n      , val2 = rnorm(n = n)\n      , log = sample(c(T,F), size = n, replace = T)\n    )\n)\n\nmicrobenchmark(\n  jsonlite = {\n    jlt \u003c- jsonlite::toJSON( x )\n  },\n  jsonify = {\n    jfy \u003c- jsonify::to_json( x )\n  },\n  times = 5\n)\n \n# Unit: milliseconds\n#      expr      min       lq     mean   median       uq      max neval\n#  jsonlite 18.52028 18.82241 19.32112 18.99683 19.18103 21.08508     5\n#   jsonify 17.72060 18.19092 19.58308 19.52457 21.14687 21.33241     5\n   \n\nmicrobenchmark(\n  jsonlite = {\n    df_jlt \u003c- jsonlite::fromJSON( jlt )\n  },\n  jsonify = {\n    df_jfy \u003c- jsonify::from_json( jfy )\n  },\n  times = 3\n)\n\n# Unit: milliseconds\n#      expr      min       lq     mean   median       uq      max neval\n#  jsonlite 62.53554 62.96435 63.12574 63.39316 63.42084 63.44853     3\n#   jsonify 42.47449 42.53826 43.38475 42.60204 43.83988 45.07773     3\n\n\n```\n\n\n### There's no `Date` type in JSON, how have you handled this?\n\nAt its core `Dates` in R are numeric, so they are treated as numbers when converted to JSON. However, the user can coerce to character through the `numeric_dates` argument. \n\n\n```{r}\ndf \u003c- data.frame(dte = as.Date(\"2018-01-01\"))\njsonify::to_json( df )\n\ndf \u003c- data.frame(dte = as.Date(\"2018-01-01\"))\njsonify::to_json( df, numeric_dates = FALSE )\n```\n\n\n\n### And `POSIXct` and `POSIXlt`?\n\nThe same\n\n```{r}\n\njsonify::to_json( as.POSIXct(\"2018-01-01 10:00:00\") )\njsonify::to_json( as.POSIXct(\"2018-01-01 10:00:00\"), numeric_dates = FALSE)\n\n```\n\nHowever, here the **POSIXct** values are returned in UTC timezone. This is by design. \n\n**POSIXlt** will return each component of the date-time\n\n```{r}\nx \u003c- as.POSIXlt(\"2018-01-01 01:00:00\", tz = \"GMT\")\njsonify::to_json( x )\n\njsonify::to_json( x, numeric_dates = FALSE)\n```\n\n\n### I see factors are converted to strings\n\nYep. Even though I constructed a `data.frame()` without setting `stringsAsFactros = FALSE`, jsonify automatically treats factors as strings. \n\n### Has this changed from v0.1?\n\nYes. And it's to keep the data more inline with modern concepts and design patterns.\n\nIf you want factors, use `factors_as_string = FALSE` in the `to_json()` call\n\n\n```{r}\njsonify::to_json( df, factors_as_string = FALSE )\n```\n\n\n### How do I install it?\n\nGet the latest release version from CRAN\n\n```{r, eval = FALSE}\ninstall.packages(\"jsonify\")\n```\n\nOr the development version from [GitHub](https://github.com/) with:\n\n```{r, eval = FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"SymbolixAU/jsonify\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSymbolixAU%2Fjsonify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSymbolixAU%2Fjsonify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSymbolixAU%2Fjsonify/lists"}