If i had the below format for a json file which is supposed to model a chemistry experiment, how do i create a joy schema to validate the json file format? there are basic examples i've seen that cover the joi schema syntax for non-nested structures, but the one below is nested and i'm not sure how to format the joi schema. Any suggestions?
{
"injection": {
"volume": {
"value": 20,
"unit": "MicroLiter"
},
"number": 1,
"location": {
"vial": "1",
"plate_row": "A",
"plate_column": "1"
}
This is a very simple use case of joi schema validation. For the above JSON
the nested schema is:
Joi.object().keys({
injection: Joi.object().keys({
number: Joi.number().required(),
volume: Joi.object().keys({
value: Joi.number().required(),
unit: Joi.string().required()
}).required(),
location: Joi.object().keys({
vial: Joi.string().required(),
plate_row: Joi.string().required(),
plate_column: Joi.string().required()
}).required()
})
});
Please let me know if this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With