-
Notifications
You must be signed in to change notification settings - Fork 11
74 lines (64 loc) · 1.78 KB
/
validate-json.yaml
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
name: Validate JSONs
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
jobs:
validate-json:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
packages:
any::jsonlite
any::jsonvalidate
any::yaml
- name: Validate JSON
run: |
# read in epiparameter database
data <- utils::read.csv(
file = file.path("inst", "extdata", "parameters.csv"),
header = TRUE
)
# convert cells with arrays to numeric
for (i in grep(pattern = "_ci_limits$", x = colnames(data))) {
if (!all(is.na(data[[i]]))) {
data[[i]] <- lapply(
strsplit(x = data[[i]], split = ",", fixed = TRUE),
as.numeric
)
}
}
data_json <- jsonlite::toJSON(
x = data,
dataframe = "columns",
na = NULL,
pretty = TRUE
)
# read schema
schema <- yaml::read_yaml(
file.path("inst", "extdata", "data_dictionary.yaml")
)
schema_json <- jsonlite::toJSON(
x = schema,
dataframe = "column",
auto_unbox = TRUE,
pretty = TRUE
)
jsonvalidate::json_validate(
json = data_json,
schema = schema_json,
engine = "ajv",
verbose = TRUE,
greedy = TRUE,
strict = TRUE,
error = TRUE
)
shell: Rscript {0}