geojsonio has two ways to validate geojson (specifically geojson, not json structure itself). Via a web API from geojsonlint, or locally using the Mapbox's javascript geojsonhint library (included in the package).
Both can act directly on many different inputs, including character strings, lists, data.frame's, all the sp
class spatial objects.
install_github("ropensci/geojsonio")
library("geojsonio")
good and bad, from character string
# good
validate('{"type": "Point", "coordinates": [-100, 80]}')
#> [1] TRUE
# bad
validate('{"type": "Rhombus", "coordinates": [[1, 2], [3, 4], [5, 6]]}')
#> [1] TRUE
from a URL
url <- "https://raw.githubusercontent.com/glynnbird/usstatesgeojson/master/california.geojson"
validate(as.location(url))
#> [1] FALSE
#> attr(,"err")
#> [1] "lexical error: invalid char in json text.\n https://raw.githubusercontent.c\n (right here) ------^\n"
bad FeatureCollection
x <- jsonlite::minify('{ "type": "FeatureCollection" }')
validate(x)
#> [1] TRUE
good and bad, from character string
# good
lint('{"type": "Point", "coordinates": [-100, 80]}')
#> [1] "valid"
# bad
lint('{"type": "Rhombus", "coordinates": [[1, 2], [3, 4], [5, 6]]}')
#> $message
#> [1] "The type Rhombus is unknown"
#>
#> $line
#> [1] 1
from a URL
url <- "https://raw.githubusercontent.com/glynnbird/usstatesgeojson/master/california.geojson"
lint(as.location(url))
#> [1] "valid"
bad FeatureCollection
x <- jsonlite::minify('{ "type": "FeatureCollection" }')
lint(x)
#> $message
#> [1] "\"features\" property required"
#>
#> $line
#> [1] 1