forked from stla/jsonStrings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
107 lines (84 loc) · 1.62 KB
/
README.Rmd
File metadata and controls
107 lines (84 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: "jsonStrings"
output: github_document
---
<!-- badges: start -->
[](https://github.com/stla/jsonStrings/actions)
<!-- badges: end -->
```{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
```