The format keyword performs a semantic validation on data. The value of this keyword must be a string, representig a format. The keyword behavior depends on the data type, meaning that the same format name for a string behaves differently on a number, or is missing, because not all data types must implement a format and usually different data types have different formats.

{
    "format": "date"
}
Input Status
"1970-01-01" valid
510 valid - not a string
"test" invalid - not a date

Provided formats

Opis JSON Schema provides all the formats for string type defined in json schema specifications.

Please note that formats starting with idn- or iri require PHP intl extension in order to work correctly.

date

A string is valid against this format if it represents a date in the following format: YYYY-MM-DD.

{
    "type": "string",
    "format": "date"
}
Input Status
"1970-01-01" valid
"Jan. 1st, 1970" invalid

time

A string is valid against this format if it represents a time in the following format: hh:mm:ss.sTZD.

{
    "type": "string",
    "format": "time"
}
Input Status
"10:05:08" valid
"10:05:08.5" valid
"10:05:08-02:30" valid
"10:05:08Z" valid
"45:60:62" invalid
"10:05" invalid
"1 pm" invalid

date-time

A string is valid against this format if it represents a date-time in the following format: YYYY:MM::DDThh:mm:ss.sTZD.

{
    "type": "string",
    "format": "date-time"
}
Input Status
"1970-01-01T10:05:08" valid
"1970-01-01T10:05:08.10" valid
"1970-01-01T10:05:08+01:00" valid
"Jan. 1st, 1970 at 1 pm" invalid

regex

A string is valid against this format if it represents a valid regular expression.

{
    "type": "string",
    "format": "regex"
}
Input Status
"^[a-z]+$" valid
"a/b" invalid - slash is not escaped
"(a" invalid - incomplete group

email

A string is valid against this format if it represents a valid e-mail address format.

{
    "type": "string",
    "format": "email"
}
Input Status
"john@example.com" valid
"john(at)example.com" invalid

idn-email

A string is valid against this format if it represents a valid idn e-mail address format.

{
    "type": "string",
    "format": "idn-email"
}
Input Status
"실례@실례.테스트" valid
"john@example.com" valid
"1234" invalid

hostname

A string is valid against this format if it represents a valid hostname.

{
    "type": "string",
    "format": "hostname"
}
Input Status
"www.example.com" valid
"xn--4gbwdl.xn--wgbh1c" valid
"not_a_valid_host_name" invalid

idn-hostname

A string is valid against this format if it represents a valid IDN hostname.

{
    "type": "string",
    "format": "idn-hostname"
}
Input Status
"실례.테스트" valid
"〮실례.테스트" invalid

ipv4

A string is valid against this format if it represents a valid IPv4 address.

{
    "type": "string",
    "format": "ipv4"
}
Input Status
"192.168.0.1" valid
"192.168.1.1.1" invalid

ipv6

A string is valid against this format if it represents a valid IPv6 address.

{
    "type": "string",
    "format": "ipv6"
}
Input Status
"::1" valid
"12345::" invalid

json-pointer

A string is valid against this format if it represents a valid (absolute) json pointer.

{
    "type": "string",
    "format": "json-pointer"
}
Input Status
"/a/b/c" valid
"/a/~" invalid

relative-json-pointer

A string is valid against this format if it represents a valid relative json pointer.

{
    "type": "string",
    "format": "relative-json-pointer"
}
Input Status
"0/a/b" valid
"5/a/b#" valid
"2#" valid
"/a/b" invalid

uri

A string is valid against this format if it represents a valid uri.

{
    "type": "string",
    "format": "uri"
}
Input Status
"http://example.com/path?qs=v&qs2[1]=3#fragment" valid
"http://a_example.com" invalid
"aaa/bbb.html" invalid

uri-reference

A string is valid against this format if it represents a valid uri or uri reference.

{
    "type": "string",
    "format": "uri-reference"
}
Input Status
"aaa/bbb.html" valid
"?a=b" valid
"#fragment" valid
"http://example.com" valid
"http://a_example.com" invalid

uri-template

A string is valid against this format if it represents a valid uri template or uri-reference.

{
    "type": "string",
    "format": "uri-template"
}
Input Status
"/{+file}.html" valid
"http://example.com/dictionary/{term:1}/{term}" valid
"{?q,lang}" valid
"http://a_example.com/file.php{?q,r}" invalid

iri

A string is valid against this format if it represents a valid IRI.

{
    "type": "string",
    "format": "iri"
}
Input Status
"http://ƒøø.ßår/?∂éœ=πîx#πîüx" valid
"http://ƒøø.com/blah_(wîkïpédiå)_blah#ßité-1" valid
"http:// ƒøø.com" invalid

iri-reference

A string is valid against this format if it represents a valid IRI reference.

{
    "type": "string",
    "format": "iri-reference"
}
Input Status
"//ƒøø.ßår/?∂éœ=πîx#πîüx" valid
"#ƒrägmênt" valid
"http://ƒøø.com/blah_(wîkïpédiå)_blah#ßité-1" valid
"\\\\WINDOWS\\filëßåré" invalid