'Cannot Extract Polygon from JSON, error in st_read

I have a file Watershed_JSON in JSON format.

headers_watershed = c('Accept-Encoding' = 'gzip',
                      `accept` = 'application/json',
                      `Authorization` = ' Token {Your API Key Here}',
                      `X-CSRFToken` = '1I2YxuQlHlxpxPM09qZTlT6vEuFgucuaTpFDpN56MksR6lttbWGjiQnwdamAw0NH',
                      `Allow` = 'GET'
)

url_1 <-paste0(URL='https://modelmywatershed.org/api/jobs/', job_ID, '/')

res_job <- GET(url=url_1, 
            add_headers(.headers = headers_watershed))

Watershed_char <- rawToChar(res_job$content)

Watershed_JSON <- fromJSON(Watershed_char, flatten = TRUE)
Watershed_JSON

####

$job_uuid
[1] "f684a0c7-debb-4adc-9510-908a9a7a98e5"

$status
[1] "complete"

$result
$result$input_pt
$result$input_pt$geometry
$result$input_pt$geometry$coordinates
[1] -102.48203   35.66726

$result$input_pt$geometry$type
[1] "Point"


$result$input_pt$properties
$result$input_pt$properties$DistStr_m
[1] 0

$result$input_pt$properties$Dist_moved
[1] 0

$result$input_pt$properties$ID
[1] 1

$result$input_pt$properties$Lat
[1] 35.66736

$result$input_pt$properties$Lon
[1] -102.4819


$result$input_pt$type
[1] "Feature"


$result$watershed
$result$watershed$geometry
$result$watershed$geometry$coordinates
 [ reached getOption("max.print") -- omitted 2 matrix slice(s) ]

$result$watershed$geometry$type
[1] "Polygon"


$result$watershed$properties
$result$watershed$properties$Area_km2
[1] 3475.114

$result$watershed$properties$GRIDCODE
NULL


$result$watershed$type
[1] "Feature"



$error
[1] ""

$started
[1] "2022-03-01T21:23:53.343710Z"

$finished
[1] "2022-03-01T21:23:55.719275Z"

I am trying to read the my file with st_read as I would like to extract the polygon shapefile found within.

Type <- Watershed_JSON$result$watershed$geometry$type
# "Polygon"
Coords <- Watershed_JSON$result$watershed$geometry$coordinates

Example <- st_read(dsn=Watershed_JSON, layer = Type)

However, when running the code, I get the following error

Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  : 
  Expecting a single value: [extent=6].
In addition: Warning message:
In if (nchar(dsn) < 1) { :
  the condition has length > 1 and only the first element will be used


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source