3 ms·
Yes you can, simply as a string. Here's your parsingMatrix from your other comment: { "if":[ { "or":[ { "===":[
by mixedCase 5y ago
Yes you can, simply as a string.
Here's your parsingMatrix from your other comment:
{
"if":[
{
"or":[
{
"===":[
{
"var":"credentialData.rapidSarsCov2PCRTest.testResult"
},
"negative"
]
},
{
"===":[
{
"var":"credentialData.covid19Vaccination.hasVaccination"
},
true
]
}
]
},
"valid",
"invalid"
]
}
Here it is rewritten in a way more similar to how a human writes Lisp:
{ "if": [{"or": [{"===":[{ "var":"credentialData.rapidSarsCov2PCRTest.testResult" }, "negative" ]},
{"===":[{ "var":"credentialData.covid19Vaccination.hasVaccination" }, true ]}]},
"valid",
"invalid"]};
Here it is as an s-expression, which you can store in a string:
(if (or (= (var "credentialData.rapidSarsCov2PCRTest.testResult") "negative")
(= (var "credentialData.covid19Vaccination.hasVaccination") #t))
"valid"
"invalid")
But, if you really have an intense hatred for adding an additional parsing step on top of the JSON, you can still improve over JsonLogic with just JSON primitives used in a cleaner way that more directly represents that s-expression.
["if", ["or", ["=", ["var", "credentialData.rapidSarsCov2PCRTest.testResult"], "negative"],
["=", ["var", "credentialData.covid19Vaccination.hasVaccination"], true]],
"valid",
"invalid"]
It's still uglier than s-expressions where you can tell symbols and strings apart with more ease, but without all the syntactical noise of JSON objects combined with arrays.
- sebmellen 5y agoThanks for the formatting, it's a lot better this way. I was using Prettier to make sure everything made sense as I a rather limited time to write the comment. Auto-formatting definitely comes with downsides... I guess that last example you demonstrated works, but I fail to see an appreciable advantage of using that over JsonLogic. It seems quite similar aside from being "cleaner," and comes with the disadvantages of not being as well defined a spec as JsonLogic. Really interesting though!