format : String
format
StringDefine and assert semantic information about a string instance.
Explanation
The format
keyword of the “format-assertion” vocabulary allows for basic semantic identification of certain kinds of string values that are commonly used. It provides a way to specify logical formats for string types, such as dates, email addresses, URIs, etc. However, it’s important to note that this vocabulary is not used by default in the official 2020-12 dialect of JSON Schema. If you want to utilize it, you would need to define your own custom dialect that includes this vocabulary.
While the format
keyword theoretically provides interoperable logical string type validation, many existing implementations may not support this vocabulary. Therefore, it’s recommended to use the format
keyword from the Format Annotation vocabulary (which is available out of the box) alongside any custom validation within the schema.
Defined Formats
Examples
{
"$schema": "https://example.com/custom-meta-schema",
"$id": "https://example.com/custom-meta-schema",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://json-schema.org/draft/2020-12/vocab/format-assertion": true
},
"allOf": [
{ "$ref": "https://json-schema.org/draft/2020-12/meta/core" },
{ "$ref": "https://json-schema.org/draft/2020-12/meta/format-assertion" }
]
}
{
"$schema": "https://example.com/custom-meta-schema",
"$id": "https://example.com/schema",
"format": "email"
}
"john.doe@example.com"
"foo_bar"
45
{ "keyword": "/format", "instance": "", "value": "email" }