Decomposition proposal #273
Replies: 2 comments 1 reply
-
You'd probably be interested in a similar proposal for array processing: json-schema-org/json-schema-spec#1323 I am personally skeptical of this sort of thing (both proposals) as it is moving too far in the direction of programming languages with the control flow (then again, I didn't want to add The correct question here is about the scope of what you can do with a JSON Schema keyword. These proposals substantially expand that scope, and it's not at all clear to me that the expansion is desirable when you take into account the additional processing complexity. For example, the expanded capabilities needed to implement |
Beta Was this translation helpful? Give feedback.
-
I'm more interested in non-homogenous array validation than sting validation, but I think solutions for one can apply to the other, so I'd be interested in reading a case-study about what you learn from implementing this as a vocabulary. Here's my advice. Although technically not forbidden, it's not a good idea to extend the functionality of existing keywords such as It's not clear what syntax you plan to use, but keep in mind that JSON objects are unordered data structures. Most implementations preserve the order of properties when parsing, but you can't rely on that across implementations. If it's important that the keywords be processed in a specific order, you'll need to use an array. |
Beta Was this translation helpful? Give feedback.
-
Like many developers, I struggle with regular expressions. They are handy and portable, but terse.
Disadvantages are:
A good example is an email validator. I could simply use format="email" but that is open to interpretation and has several obscure regular expressions.
In a private project, I am working, on an extension to the schema that would allow an alternative method of pattern matching. If the json schema were extended with a "decomposition" object type, which would act as both a string and array. For example:
{ "$ref": "$defs/localPart" },
{ "$ref": "$defs/domainPart" }
],
It is first evaluated as a string (minLength, maxLength)
Then it is split based on new property "split" (character, sequence, or null)
Then it is evaluated as an array (minItems, maxItems, items, prefixItems, [suffixItems!] )
Those could be recursively evaluated as string regexes or other compositions.
I believe this approach would allow complex strings to be evaluated as json schema objects, with very little change in the existing schema specification. One could argue that strings are not part of a json schema, which would be valid, but we already validate them with regular expressions - this would be just an alternative method: more explicit and intentional.
Of course, it needs more discussion to understand:
(please don't respond and say regex's do this; read my opinion on their limitations above)
Beta Was this translation helpful? Give feedback.
All reactions