Replies: 2 comments 3 replies
-
In essence, you propose to explicitly add a type system to JSON Logic. There are some downsides to this. Bloating of the rule definitions is one, but the type system also represents a significant addition to the specification. An alternative would be to have a type-checking operation: at least then you don't have to overload the existing If you want to stay on the static side of things, you could also think of validating (a set of) rules against a given JSON Schema (or some other JSON spec. format), or vice versa: deriving a JSON Schema (or some other JSON spec. format) from (a set of) rules. |
Beta Was this translation helpful? Give feedback.
-
I need some time to fully digest this. Incorporating type information into the AST could lead to better optimizations in the runtime performance, and some better safety, but requires a lot of scaffolding to make use of it. My implementation actually does have some primitive checking at build time for certain operators (though it only validates on values it could acquire at comp-time), logic.build({
'+': ['hi', { val: 'a' }]
}) Would error at build time, rather than at run time, because of checks it performs at compile time for that operator. My gut reaction to just validating -- I need some time to digest, I could see us adding a Community Extension to JSON Logic that introduces validation operators. But I think mandating a comp-time type system to JSON Logic might require an aggressive rewrite of every implementation, so I'm uncertain if that's the direction we'd take for JSON Logic Core. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This may relate to #18 .
JSON Logic is, reasonably, designed around JSOs, which are very dynamic and flexible. But for many languages, that flexibility is not built in, and so only represents a potential source of error which the host language is designed to prevent, so using JSON Logic introduces a new class of error. The use case I'm thinking of is that a server knows the type which will be passed in to the rule, but has to accept the rule from an external source. It would be nice to be able to immediately validate the rule itself against the known input type, rather than have to fabricate an input instance and wait for an error.
A half-baked proposal is to optionally allow type information in a
"var"
(or"val"
) block, probably in typescript, JSDoc, or even JSONSchema format. Something likeAn implementation in a statically typed language could parse the rule for those
type
fields and check them against the types of the fields.Downsides are that this could lead to bloating of the rules, especially if type information is repeated (in which case it could also be self-conflicting, although this could also be detected at rule "compile time"). It may be awkward to actually implement even in static languages if they don't have runtime reflection.
Beta Was this translation helpful? Give feedback.
All reactions