Say we have a schema which defines certain data. Let's say it's a "credential" which is a "COVID-19 Back to Work Credential." The credential is valid in the case that someone either 1) has a COVID vaccination or 2) has a negative COVID test in the past 72 hours. That data might look like this:
{
"credentialName": "COVID-19 Back to Work Credential",
"credentialIssuer": "Acme Labs Inc.",
"credentialData": {
"rapidSarsCov2PCRTest": {
"hasTestResult": true,
"testResult": "negative",
"testTime": 1622145851
},
"covid19Vaccination": {
"hasVaccination": false
}
}
}
Now, say I want to define the conditions under which this "credential" is valid or invalid, but I want to include this "matrix" within the schema (not any business logic, just matrix logic that pertains to the data within the schema itself).Optimally, I'd be able to do this within the same schema or file.
With JsonLogic, that might look like this (probably flawed logic, just a demo, not using this in production, may cause your computer to go up in flames, etc.):
{
...
"parsingMatrix": {
"if": [
{
"or": [
{
"===": [
{ "var": "credentialData.rapidSarsCov2PCRTest.testResult" },
"negative"
]
},
{
"===": [
{ "var": "credentialData.covid19Vaccination.hasVaccination" },
true
]
}
]
},
"valid",
"invalid"
]
}
}
Can you think of another way to do this that doesn't rely on using JsonLogic or something like it (or a cleaner method for doing it in JSON)?