This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.Rmd
119 lines (83 loc) · 3.32 KB
/
README.Rmd
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
108
109
110
111
112
113
114
115
116
117
118
119
geojsonlint
===========
```{r echo=FALSE}
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
warning = FALSE,
message = FALSE
)
```
[![cran checks](https://cranchecks.info/badges/worst/geojsonlint)](https://cranchecks.info/pkgs/geojsonlint)
[![R-check](https://github.com/ropensci/geojsonlint/workflows/R-check/badge.svg)](https://github.com/ropensci/geojsonlint/actions?query=workflow%3AR-check)
[![codecov.io](https://codecov.io/github/ropensci/geojsonlint/coverage.svg?branch=master)](https://codecov.io/github/ropensci/geojsonlint?branch=master)
[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/geojsonlint)](https://github.com/metacran/cranlogs.app)
[![cran version](https://www.r-pkg.org/badges/version/geojsonlint)](https://cran.r-project.org/package=geojsonlint)
GeoJSON linters available in `geojsonlint`
* [GeoJSON hint JS library](https://www.npmjs.com/package/geojsonhint) - via `geojson_hint()` - currently using `geojsonhint` `v1.2.1`
* [is-my-json-valid JS library](https://www.npmjs.com/package/is-my-json-valid) - via `geojson_validate()`
Both functions return the same outputs. If the GeoJSON is valid, they return `TRUE`.
If the GeoJSON is invalid, they return `FALSE`, plus reason(s) that the GeoJSON is invalid
in an attribute named _errors_ as a data.frame. The fields in the data.frame's are not
the same across functions unfortunately, but they can be easily coerced to combine via
e.g., `plyr::rbind.fill` or `dplyr::bind_rows` or `data.table::rbindlist(fill = TRUE)`
The parameters for the three functions are similar, though `geojson_validate()` has an
extra parameter `greedy` that's not available in the others.
## Installation
from CRAN
```{r eval=FALSE}
install.packages("geojsonlint")
```
Dev version
```{r eval=FALSE}
remotes::install_github("ropensci/geojsonlint")
```
```{r}
library("geojsonlint")
```
## Good GeoJSON
geojsonhint JS library
```{r}
geojson_hint(x = '{"type": "Point", "coordinates": [-100, 80]}')
```
is-my-json-valid JS library
```{r}
geojson_validate(x = '{"type": "Point", "coordinates": [-100, 80]}')
```
## Bad GeoJSON
geojsonhint JS library
```{r}
geojson_hint('{"type": "FooBar"}')
```
is-my-json-valid JS library
```{r}
geojson_validate('{ "type": "FeatureCollection" }')
```
## Bad GeoJSON - with reason for failure
geojsonhint JS library
```{r}
geojson_hint('{"type": "FooBar"}', inform = TRUE)
```
is-my-json-valid JS library
```{r}
geojson_validate('{ "type": "FeatureCollection" }', inform = TRUE)
```
## Bad GeoJSON - stop on validation failure
geojsonhint JS library
```{r eval=FALSE}
geojson_hint('{"type": "FooBar"}', error = TRUE)
#> Error: Line 1
#> - The type FooBar is unknown
```
is-my-json-valid JS library
```{r eval=FALSE}
geojson_validate('{ "type": "FeatureCollection" }', error = TRUE)
#> Error: 1 error validating json:
#> - data: no (or more than one) schemas match
```
## Meta
* Please [report any issues or bugs](https://github.com/ropensci/geojsonlint/issues).
* License: MIT
* Get citation information for `geojsonlint` in R doing `citation(package = 'geojsonlint')`
* Please note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms.
[![rofooter](https://ropensci.org/public_images/github_footer.png)](https://ropensci.org)