{"id":18174459,"url":"https://github.com/r-lib/cereal","last_synced_at":"2025-04-22T00:31:40.884Z","repository":{"id":168398252,"uuid":"643999023","full_name":"r-lib/cereal","owner":"r-lib","description":"Serialize vctrs objects to JSON 🥣","archived":false,"fork":false,"pushed_at":"2023-06-09T14:56:25.000Z","size":905,"stargazers_count":25,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-24T12:48:44.413Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://r-lib.github.io/cereal/","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/r-lib.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":"2023-05-22T15:36:57.000Z","updated_at":"2024-08-28T20:58:45.000Z","dependencies_parsed_at":"2023-07-11T07:15:20.044Z","dependency_job_id":null,"html_url":"https://github.com/r-lib/cereal","commit_stats":null,"previous_names":["juliasilge/cereal","r-lib/cereal"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fcereal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fcereal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fcereal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fcereal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-lib","download_url":"https://codeload.github.com/r-lib/cereal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223883600,"owners_count":17219270,"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":[],"created_at":"2024-11-02T16:03:07.463Z","updated_at":"2024-11-09T21:08:24.063Z","avatar_url":"https://github.com/r-lib.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# cereal 🥣\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/r-lib/cereal/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/cereal/actions/workflows/R-CMD-check.yaml)\n[![CRAN status](https://www.r-pkg.org/badges/version/cereal)](https://CRAN.R-project.org/package=cereal)\n[![Codecov test coverage](https://codecov.io/gh/r-lib/cereal/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/cereal?branch=main)\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n\u003c!-- badges: end --\u003e\n\nThe goal of cereal is to provide methods to [serialize](https://en.wikipedia.org/wiki/Serialization) objects from [vctrs](https://vctrs.r-lib.org/) to [JSON](https://en.wikipedia.org/wiki/JSON), as well as back from JSON to vctrs objects.\n\n## Installation\n\nYou can install the released version of vetiver from\n[CRAN](https://CRAN.R-project.org) with:\n\n``` r\ninstall.packages(\"cereal\")\n```\n\nYou can install the development version of cereal from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"pak\")\npak::pak(\"r-lib/cereal\")\n```\n\n## Example\n\nA data frame is a rectangular collection of variables (in the columns) and observations (in the rows). Each variable is a vector of one data type, like factor or datetime: \n\n```{r example}\ndf \u003c- tibble::tibble(\n  a = c(1.2, 2.3, 3.4),\n  b = 2L:4L,\n  c = Sys.Date() + 0:2,\n  d = as.POSIXct(\"2019-01-01\", tz = \"America/New_York\") + 100:102,\n  e = sample(letters, 3),\n  f = factor(c(\"blue\", \"blue\", \"green\"), levels = c(\"blue\", \"green\", \"red\")),\n  g = ordered(c(\"small\", \"large\", \"medium\"), levels = c(\"small\", \"medium\", \"large\"))\n)\n\ndf\n```\n\nThe vctrs package has a [concept of a **vector prototype**](https://vctrs.r-lib.org/articles/type-size.html) which captures the metadata associated with a vector without keeping any of the data itself.\n\n```{r cars}\nvctrs::vec_ptype(df)\n```\n\nThe information stored in such a vector prototype includes, for example, the levels of a factor and the timezone for a datetime. This can be useful or important information when deploying code or models, such as when using [vetiver](https://vetiver.rstudio.com/). We could store this vector prototype as an R binary object saved as an `.rds` file, but with cereal, you can store this vector prototype in plain text as JSON:\n\n```{r}\nlibrary(cereal)\njson \u003c- cereal_to_json(df)\njson\n```\n\nStoring prototype information as JSON (rather than a binary file) means it can be used as plain-text metadata for a model. \n\nYou can also convert from JSON back to the original prototype:\n\n```{r}\ncereal_from_json(json)\n```\n\nFor an approach to this same task using Python, [see Pydantic's `model.json()`](https://docs.pydantic.dev/latest/usage/exporting_models/#modeljson).\n\n## Contributing\n\n- This project is released with a [Contributor Code of Conduct](https://www.contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n\n- If you think you have encountered a bug, please [submit an issue](https://github.com/r-lib/cereal/issues).\n\n- Either way, learn how to create and share a [reprex](https://reprex.tidyverse.org/articles/articles/learn-reprex.html) (a minimal, reproducible example), to clearly communicate about your code.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fcereal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-lib%2Fcereal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fcereal/lists"}