Download the code for this exercise
Access the open standard for camera trap data and download Supplementary Material 3, the JSON template. Save the file to your project directory.
jsonlite
package. There is much more
about the relationship between data representation in R and JSON
in the accompanying paper.
install.packages('jsonlite')
library(jsonlite)
?jsonlite
## read in a json schema ####
template <- fromJSON('oo_99336.json')
str(template)
template$CameraTrapMetadataStandard
## combining datasets to match schema definitions ####
myImages <- list(Project = data.frame(ProjectID = 'thelindyardproject.org',
ProjectName = 'Lind backyard Summer 2017',
ProjectObjectives = 'Find out who has been eating my lettuces'),
Deployment = data.frame(CameraDeploymentID = c(1:3),
CameraDeploymentBeginDate = c('2017-06-01',
'2017-06-07',
'2017-06-10'),
DeploymentLocationID = 'Shed wall'
),
Images = data.frame(imageID = 1:10,
dateTimeCaptured = sample(seq.Date(from = as.Date('2017-06-01'),
to = as.Date('2017-07-01'),
by = 1), 10, replace = T),
photoType = c('Staff', rep('Animal', 4), 'Unidentifiable',
rep('Animal', 4)),
photoTypeIdentifiedBy = 'Eric Lind'),
ImageAnimal = data.frame(imageID = c(rep(2, 2), 3, 4, 6:10),
imageCount = 1,
speciesScientificName = c('Vulpes vulpes', rep('Sylvilagus floridanus', 8)))
)
myImages
toJSON(myImages, pretty = T)
toJSON(template, pretty = T)