Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stla/jsonStrings
Manipulate JSON strings in R.
https://github.com/stla/jsonStrings
json r rcpp
Last synced: 30 days ago
JSON representation
Manipulate JSON strings in R.
- Host: GitHub
- URL: https://github.com/stla/jsonStrings
- Owner: stla
- Created: 2021-05-18T20:14:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-05T05:52:53.000Z (about 2 years ago)
- Last Synced: 2024-08-03T22:18:18.859Z (4 months ago)
- Topics: json, r, rcpp
- Language: C++
- Homepage:
- Size: 298 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
- jimsghstars - stla/jsonStrings - Manipulate JSON strings in R. (C++)
README
---
title: "jsonStrings"
output: github_document
---[![R-CMD-check](https://github.com/stla/jsonStrings/workflows/R-CMD-check/badge.svg)](https://github.com/stla/jsonStrings/actions)
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE)
``````{r package}
library(jsonStrings)
```## Define a JSON string
```{r jsonstring}
jstring <- jsonString$new("
{
\"foo\": \"hello\",
\"bar\": {\"x\": 1, \"y\": 2},
\"baz\": [9, 99, null],
\"qux\": [null, [0, 1], {\"a\": 1000}]
}
")
```## Extract a JSON value
```{r}
jstring$at("foo")
jstring$at("bar", "y")
jstring$at("baz", 2)
```## Erase a JSON value
```{r}
jstring$erase("baz")
jstring
```## Check existence of a property
```{r}
jstring$hasKey("bar")
```## Check a type
```{r}
jstring$is("object")
```## Add a property
```{r}
jstring$addProperty("new", "[4,5]")
jstring
```## Update a JSON string
```{r}
jstring$update(
"{
\"foo\": \"goodbye\",
\"quux\": 10000
}"
)
jstring
```## Patch a JSON string
```{r}
jspatch <- "[
{\"op\": \"remove\", \"path\": \"/foo\"},
{\"op\": \"replace\", \"path\": \"/qux/2\", \"value\": 9999}
]"
jstring$patch(jspatch)
```## Chaining
```{r}
jstring <- jsonString$new("
{
\"foo\": \"hello\",
\"bar\": {\"x\": 1, \"y\": 2},
\"baz\": [9, 99, null],
\"qux\": [null, [0, 1], {\"a\": 1000}]
}
")
jstring$erase("baz")$addProperty("new", "[4,5]")$update(
"{
\"foo\": \"goodbye\",
\"quux\": 10000
}"
)
jstring
```