Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vignette on parsing error messages #7

Open
collinschwantes opened this issue Feb 12, 2025 · 1 comment
Open

vignette on parsing error messages #7

collinschwantes opened this issue Feb 12, 2025 · 1 comment

Comments

@collinschwantes
Copy link
Collaborator

the validate json error messages are not ergonomic and require background to be able to parse

@collinschwantes
Copy link
Collaborator Author

Validating individual properties

Sometimes, error messages can be overwhelming and its helpful to validate a
particular component of the schema. We can use the reference argument in
json_validator to only validate against part of the schema. This is extremely
helpful if you want to isolate validation issues.

For example, creators are tricky because they have subcomponents. Lets modify
a creator object and check if its still properly formatted.


project_metadata_broken_creator <- project_metadata_list_entities

creator_1 <- project_metadata_broken_creator$creators[[1]]

# lets enter the ORCID as a number
creator_1$nameIdentifier <- 343158628

project_metadata_broken_creator$creators[[1]] <- creator_1

project_metadata_json <- prep_for_json(project_metadata_list_entities) |>
  jsonlite::toJSON(pretty  = TRUE)
schema <- here::here("inst/extdata/wdds_schema/schemas/datacite/datacite-v4.5.json")

creator_validator <- jsonvalidate::json_validator(schema,engine = "ajv",reference ="#/definitions/creator")

debugonce(creator_validator)

project_validation <- creator_validator(project_metadata_json,verbose = TRUE)

## check for errors!

errors <- attributes(project_validation)

if(!project_validation){
  errors$errors  
} else {
  print("Valid project metadata!😁")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant