Skip to content

Whether the format and pattern keywords can exist simultaneously under the string type #262

Answered by handrews
suncpp asked this question in Q&A
Discussion options

You must be logged in to vote

@suncpp all JSON Schema keywords can be used together, and they all have the same priority. Some of these combinations make sense, and some do not (e.g. minimum is superfluous in {"type": "string", "minimum": 2} because any number will fail the type assertion), but none are forbidden.

pattern and format are often used together because depending on the draft and configuration you are using, format may or may not behave as an assertion. And even if it does, that keyword is pretty unreliable as it's not implemented consistently.

So people often use format as a semantic annotation (its default behavior in 2020-12) and use pattern to do the actual validation. e.g. {"type": "string", "format": …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@suncpp
Comment options

Answer selected by suncpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants