json-schema-typed
- Version 9.0.0
- Published
- 300 kB
- No dependencies
- BSD-3-Clause license
Install
npm i json-schema-typedyarn add json-schema-typedpnpm add json-schema-typedOverview
JSON Schema TypeScript definitions with complete inline documentation.
Index
Variables
Enums
Type Aliases
Namespaces
Variables
variable $schema
const $schema: string;variable draft
const draft: string;variable keywords
const keywords: readonly [ '$anchor', '$comment', '$defs', '$dynamicAnchor', '$dynamicRef', '$id', '$recursiveAnchor', '$recursiveRef', '$ref', '$schema', '$vocabulary', 'additionalItems', 'additionalProperties', 'allOf', 'anyOf', 'const', 'contains', 'contentEncoding', 'contentMediaType', 'contentSchema', 'default', 'definitions', 'dependencies', 'dependentRequired', 'dependentSchemas', 'deprecated', 'description', 'else', 'enum', 'examples', 'exclusiveMaximum', 'exclusiveMinimum', 'format', 'if', 'items', 'maxContains', 'maximum', 'maxItems', 'maxLength', 'maxProperties', 'minContains', 'minimum', 'minItems', 'minLength', 'minProperties', 'multipleOf', 'not', 'oneOf', 'pattern', 'patternProperties', 'prefixItems', 'properties', 'propertyNames', 'readOnly', 'required', 'then', 'title', 'type', 'unevaluatedItems', 'unevaluatedProperties', 'uniqueItems', 'writeOnly'];Enums
enum ContentEncoding
enum ContentEncoding { '7bit' = '7bit', '8bit' = '8bit', Base16 = 'base16', Base32 = 'base32', Base32Hex = 'base32hex', Base64 = 'base64', Base64URL = 'base64url', Binary = 'binary', IETFToken = 'ietf-token', QuotedPrintable = 'quoted-printable', XToken = 'x-token',}Content encoding strategy enum.
- [RFC 4648: The Base16, Base32, and Base64 Data Encodings](https://datatracker.ietf.org/doc/html/rfc4648) - [Content-Transfer-Encoding Syntax](https://datatracker.ietf.org/doc/html/rfc2045#section-6.1) - [7bit vs 8bit encoding](https://stackoverflow.com/questions/25710599/content-transfer-encoding-7bit-or-8-bit/28531705#28531705)
member "7bit"
'7bit' = '7bit'Only US-ASCII characters, which use the lower 7 bits for each character.
Each line must be less than 1,000 characters.
member "8bit"
'8bit' = '8bit'Allow extended ASCII characters which can use the 8th (highest) bit to indicate special characters not available in 7bit.
Each line must be less than 1,000 characters.
member Base16
Base16 = 'base16'Hexadecimal encoding using the alphabet
0-9A-F, as defined by [RFC 4648, Section 8](https://datatracker.ietf.org/doc/html/rfc4648#section-8).
member Base32
Base32 = 'base32'Base 32 encoding using the alphabet
A-Z2-7, as defined by [RFC 4648, Section 6](https://datatracker.ietf.org/doc/html/rfc4648#section-6).
member Base32Hex
Base32Hex = 'base32hex'Base 32 encoding using the "Extended Hex" alphabet
0-9A-V, as defined by [RFC 4648, Section 7](https://datatracker.ietf.org/doc/html/rfc4648#section-7).
member Base64
Base64 = 'base64'Base 64 encoding as defined by [RFC 4648, Section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4). Useful for data that is mostly non-text. Where RFC 2045 and RFC 4648 differ, the RFC 4648 definition (no line length limit) SHOULD be assumed.
member Base64URL
Base64URL = 'base64url'Base 64 encoding with the URL and filename safe alphabet (
-and_instead of+and/), as defined by [RFC 4648, Section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5).
member Binary
Binary = 'binary'Same character set as 8bit, with no line length restriction.
member IETFToken
IETFToken = 'ietf-token'An extension token defined by a standards-track RFC and registered with IANA.
member QuotedPrintable
QuotedPrintable = 'quoted-printable'Lines are limited to 76 characters, and line breaks are represented using special characters that are escaped.
member XToken
XToken = 'x-token'The two characters "X-" or "x-" followed, with no intervening white space, by any token.
enum Format
enum Format { Date = 'date', DateTime = 'date-time', Duration = 'duration', Email = 'email', Hostname = 'hostname', IDNEmail = 'idn-email', IDNHostname = 'idn-hostname', IPv4 = 'ipv4', IPv6 = 'ipv6', IRI = 'iri', IRIReference = 'iri-reference', JSONPointer = 'json-pointer', JSONPointerURIFragment = 'json-pointer-uri-fragment', RegEx = 'regex', RelativeJSONPointer = 'relative-json-pointer', Time = 'time', URI = 'uri', URIReference = 'uri-reference', URITemplate = 'uri-template', UUID = 'uuid',}This enum provides well-known formats that apply to strings.
member Date
Date = 'date'A string instance is valid against this attribute if it is a valid representation according to the "full-date" ABNF rule in [RFC 3339][RFC3339].
[RFC3339]: https://datatracker.ietf.org/doc/html/rfc3339
member DateTime
DateTime = 'date-time'A string instance is valid against this attribute if it is a valid representation according to the "date-time" ABNF rule in [RFC 3339][RFC3339].
[RFC3339]: https://datatracker.ietf.org/doc/html/rfc3339
member Duration
Duration = 'duration'A string instance is valid against this attribute if it is a valid representation according to the "duration" ABNF rule in [RFC 3339][RFC3339].
[RFC3339]: https://datatracker.ietf.org/doc/html/rfc3339
member Email
Email = 'email'A string instance is valid against this attribute if it is a valid Internet email address as defined by the "Mailbox" ABNF rule in [RFC 5321][RFC5321], section 4.1.2.
[RFC5321]: https://datatracker.ietf.org/doc/html/rfc5321
member Hostname
Hostname = 'hostname'As defined by [RFC 1123, section 2.1][RFC1123], including host names produced using the Punycode algorithm specified in [RFC 5891, section 4.4][RFC5891].
[RFC1123]: https://datatracker.ietf.org/doc/html/rfc1123 [RFC5891]: https://datatracker.ietf.org/doc/html/rfc5891
member IDNEmail
IDNEmail = 'idn-email'A string instance is valid against this attribute if it is a valid Internet email address as defined by the extended "Mailbox" ABNF rule in [RFC 6531][RFC6531], section 3.3.
[RFC6531]: https://datatracker.ietf.org/doc/html/rfc6531
member IDNHostname
IDNHostname = 'idn-hostname'As defined by either [RFC 1123, section 2.1][RFC1123] as for hostname, or an internationalized hostname as defined by [RFC 5890, section 2.3.2.3][RFC5890].
[RFC1123]: https://datatracker.ietf.org/doc/html/rfc1123 [RFC5890]: https://datatracker.ietf.org/doc/html/rfc5890
member IPv4
IPv4 = 'ipv4'An IPv4 address according to the "dotted-quad" ABNF syntax as defined in [RFC 2673, section 3.2][RFC2673].
[RFC2673]: https://datatracker.ietf.org/doc/html/rfc2673
member IPv6
IPv6 = 'ipv6'An IPv6 address as defined in [RFC 4291, section 2.2][RFC4291].
[RFC4291]: https://datatracker.ietf.org/doc/html/rfc4291
member IRI
IRI = 'iri'A string instance is valid against this attribute if it is a valid IRI, according to [RFC 3987][RFC3987].
[RFC3987]: https://datatracker.ietf.org/doc/html/rfc3987
member IRIReference
IRIReference = 'iri-reference'A string instance is valid against this attribute if it is a valid IRI Reference (either an IRI or a relative-reference), according to [RFC 3987][RFC3987].
[RFC3987]: https://datatracker.ietf.org/doc/html/rfc3987
member JSONPointer
JSONPointer = 'json-pointer'A string instance is valid against this attribute if it is a valid JSON string representation of a JSON Pointer, according to [RFC 6901, section 5][RFC6901].
[RFC6901]: https://datatracker.ietf.org/doc/html/rfc6901
member JSONPointerURIFragment
JSONPointerURIFragment = 'json-pointer-uri-fragment'A string instance is valid against this attribute if it is a valid JSON string representation of a JSON Pointer fragment, according to [RFC 6901, section 5][RFC6901].
[RFC6901]: https://datatracker.ietf.org/doc/html/rfc6901
member RegEx
RegEx = 'regex'This attribute applies to string instances.
A regular expression, which SHOULD be valid according to the [ECMA-262][ecma262] regular expression dialect.
Implementations that validate formats MUST accept at least the subset of [ECMA-262][ecma262] defined in the [Regular Expressions][regexInterop] section of this specification, and SHOULD accept all valid [ECMA-262][ecma262] expressions.
[ecma262]: https://www.ecma-international.org/publications-and-standards/standards/ecma-262/ [regexInterop]: https://json-schema.org/draft/2020-12/json-schema-validation.html#regexInterop
member RelativeJSONPointer
RelativeJSONPointer = 'relative-json-pointer'A string instance is valid against this attribute if it is a valid [Relative JSON Pointer][relative-json-pointer].
[relative-json-pointer]: https://datatracker.ietf.org/doc/html/draft-handrews-relative-json-pointer-01
member Time
Time = 'time'A string instance is valid against this attribute if it is a valid representation according to the "full-time" ABNF rule in [RFC 3339][RFC3339].
[RFC3339]: https://datatracker.ietf.org/doc/html/rfc3339
member URI
URI = 'uri'A string instance is valid against this attribute if it is a valid URI, according to [RFC3986][RFC3986].
[RFC3986]: https://datatracker.ietf.org/doc/html/rfc3986
member URIReference
URIReference = 'uri-reference'A string instance is valid against this attribute if it is a valid URI Reference (either a URI or a relative-reference), according to [RFC3986][RFC3986].
[RFC3986]: https://datatracker.ietf.org/doc/html/rfc3986
member URITemplate
URITemplate = 'uri-template'A string instance is valid against this attribute if it is a valid URI Template (of any level), according to [RFC 6570][RFC6570].
Note that URI Templates may be used for IRIs; there is no separate IRI Template specification.
[RFC6570]: https://datatracker.ietf.org/doc/html/rfc6570
member UUID
UUID = 'uuid'A string instance is valid against this attribute if it is a valid string representation of a UUID, according to [RFC 4122][RFC4122].
[RFC4122]: https://datatracker.ietf.org/doc/html/rfc4122
enum TypeName
enum TypeName { Array = 'array', Boolean = 'boolean', Integer = 'integer', Null = 'null', Number = 'number', Object = 'object', String = 'string',}Enum consisting of simple type names for the
typekeyword
member Array
Array = 'array'Value MUST be an array.
member Boolean
Boolean = 'boolean'Value MUST be a boolean.
member Integer
Integer = 'integer'Value MUST be an integer, no floating point numbers are allowed. This is a subset of the number type.
member Null
Null = 'null'Value MUST be null. Note this is mainly for purpose of being able use union types to define nullability. If this type is not included in a union, null values are not allowed (the primitives listed above do not allow nulls on their own).
member Number
Number = 'number'Value MUST be a number, floating point numbers are allowed.
member Object
Object = 'object'Value MUST be an object.
member String
String = 'string'Value MUST be a string.
Type Aliases
type JSONSchema
type JSONSchema<Value = any, SchemaType = PermissiveSchemaType<Value>> = | boolean | JSONSchema.Interface<Value, SchemaType>;JSON Schema [Draft 2020-12](https://json-schema.org/draft/2020-12/json-schema-validation.html)
A schema is either a boolean or an object of keywords. Every keyword is optional and documented inline.
-
JSONSchema— any schema. -JSONSchema<Value>— a schema for a particular kind of value;typeis constrained accordingly (JSONSchema<string>hastype?: "string"). -JSONSchema.String,JSONSchema.Object, ... — only the keywords that apply to that type.
Namespaces
namespace JSONSchema
namespace JSONSchema {}interface Interface
interface Interface< Value = any, SchemaType = TypeValue | (string & {}), Sub = JSONSchema> {}The complete set of keywords for this draft. Every keyword is optional. The
typekeyword is constrained toSchemaType; nested schemas are typed asSub(JSONSchemaunless specified, so that a type extending this interface can also be used for nested schemas).This is the object half of
JSONSchema; extend it to add custom keywords.
property $anchor
$anchor?: string;Using JSON Pointer fragments requires knowledge of the structure of the schema. When writing schema documents with the intention to provide re-usable schemas, it may be preferable to use a plain name fragment that is not tied to any particular structural location. This allows a subschema to be relocated without requiring JSON Pointer references to be updated.
The
$anchorkeyword is used to specify such a fragment. It is an identifier keyword that can only be used to create plain name fragments.If present, the value of this keyword MUST be a string, which MUST start with a letter
[A-Za-z], followed by any number of letters, digits[0-9], hyphens-, underscores_, colons:, or periods..Note that the anchor string does not include the
#character, as it is not a URI-reference. An{"$anchor": "foo"}becomes the fragment#foowhen used in a URI.The base URI to which the resulting fragment is appended is determined by the
$idkeyword as explained in the previous section. Two$anchorkeywords in the same schema document MAY have the same value if they apply to different base URIs, as the resulting full URIs will be distinct. However, the effect of two$anchorkeywords with the same value and the same base URI is undefined. Implementations MAY raise an error if such usage is detected.
property $comment
$comment?: string;This keyword reserves a location for comments from schema authors to readers or maintainers of the schema.
The value of this keyword MUST be a string. Implementations MUST NOT present this string to end users. Tools for editing schemas SHOULD support displaying and editing this keyword. The value of this keyword MAY be used in debug or error output which is intended for developers making use of schemas.
Schema vocabularies SHOULD allow
$commentwithin any object containing vocabulary keywords. Implementations MAY assume$commentis allowed unless the vocabulary specifically forbids it. Vocabularies MUST NOT specify any effect of$commentbeyond what is described in this specification.Tools that translate other media types or programming languages to and from
application/schema+jsonMAY choose to convert that media type or programming language's native comments to or from$commentvalues. The behavior of such translation when both native comments and$commentproperties are present is implementation-dependent.Implementations MAY strip
$commentvalues at any point during processing. In particular, this allows for shortening schemas when the size of deployed schemas is a concern.Implementations MUST NOT take any other action based on the presence, absence, or contents of
$commentproperties. In particular, the value of$commentMUST NOT be collected as an annotation result.
property $defs
$defs?: Record<string, Sub>;The
$defskeyword reserves a location for schema authors to inline re-usable JSON Schemas into a more general schema. The keyword does not directly affect the validation result.This keyword's value MUST be an object. Each member value of this object MUST be a valid JSON Schema.
property $dynamicAnchor
$dynamicAnchor?: string;The
$dynamicAnchorindicates that the fragment is an extension point when used with the$dynamicRefkeyword. This low-level, advanced feature makes it easier to extend recursive schemas such as the meta-schemas, without imposing any particular semantics on that extension. See$dynamicReffor more details.
property $dynamicRef
$dynamicRef?: string;The
$dynamicRefkeyword is an applicator that allows for deferring the full resolution until runtime, at which point it is resolved each time it is encountered while evaluating an instance.Together with
$dynamicAnchor,$dynamicRefimplements a cooperative extension mechanism that is primarily useful with recursive schemas (schemas that reference themselves). Both the extension point and the runtime-determined extension target are defined with$dynamicAnchor, and only exhibit runtime dynamic behavior when referenced with$dynamicRef.The value of the
$dynamicRefproperty MUST be a string which is a URI-Reference. Resolved against the current URI base, it produces the URI used as the starting point for runtime resolution. This initial resolution is safe to perform on schema load.If the initially resolved starting point URI includes a fragment that was created by the
$dynamicAnchorkeyword, the initial URI MUST be replaced by the URI (including the fragment) for the outermost schema resource in the [dynamic scope][scopes] that defines an identically named fragment with$dynamicAnchor.Otherwise, its behavior is identical to
$ref, and no runtime resolution is needed.[scopes]: https://json-schema.org/draft/2020-12/json-schema-core.html#scopes
"uri-reference"
property $id
$id?: string;The
$idkeyword identifies a schema resource with its [canonical][RFC6596] URI.Note that this URI is an identifier and not necessarily a network locator. In the case of a network-addressable URL, a schema need not be downloadable from its canonical URI.
If present, the value for this keyword MUST be a string, and MUST represent a valid [URI-reference][RFC3986]. This URI-reference SHOULD be normalized, and MUST resolve to an [absolute-URI][RFC3986] (without a fragment), or to a URI with an empty fragment.
The empty fragment form is NOT RECOMMENDED and is retained only for backwards compatibility, and because the
application/schema+jsonmedia type defines that a URI with an empty fragment identifies the same resource as the same URI with the fragment removed. However, since this equivalence is not part of the [RFC 3986 normalization process][RFC3986], implementers and schema authors cannot rely on generic URI libraries understanding it.Therefore,
$idMUST NOT contain a non-empty fragment, and SHOULD NOT contain an empty fragment. The absolute-URI form MUST be considered the canonical URI, regardless of the presence or absence of an empty fragment.The absolute-URI also serves as the base URI for relative URI-references in keywords within the schema resource, in accordance with [RFC 3986][RFC3986] section 5.1.1 regarding base URIs embedded in content.
The presence of
$idin a subschema indicates that the subschema constitutes a distinct schema resource within a single schema document. Furthermore, in accordance with [RFC 3986][RFC3986] section 5.1.2 regarding encapsulating entities, if an$idin a subschema is a relative URI-reference, the base URI for resolving that reference is the URI of the parent schema resource.If no parent schema object explicitly identifies itself as a resource with
$id, the base URI is that of the entire document.The root schema of a JSON Schema document SHOULD contain an
$idkeyword with an [absolute-URI][RFC3986] (containing a scheme, but no fragment).[RFC6596]: https://datatracker.ietf.org/doc/html/rfc6596 [RFC3986]: https://datatracker.ietf.org/doc/html/rfc3986
"uri-reference"
property $recursiveAnchor
$recursiveAnchor?: boolean;Draft 2019-09 keyword, replaced by
$dynamicAnchorin draft 2020-12. It is still listed in the draft 2020-12 meta-schema for compatibility.false
Deprecated
$recursiveAnchorhas been replaced by$dynamicAnchor.
property $recursiveRef
$recursiveRef?: string;Draft 2019-09 keyword, replaced by
$dynamicRefin draft 2020-12. It is still listed in the draft 2020-12 meta-schema for compatibility.Deprecated
$recursiveRefhas been replaced by$dynamicRef. "uri-reference"
property $ref
$ref?: string;The
$refkeyword is an applicator that is used to reference a statically identified schema. Its results are the results of the referenced schema. Other keywords can appear alongside of$refin the same schema object.The value of the
$refproperty MUST be a string which is a URI-Reference. Resolved against the current URI base, it produces the URI of the schema to apply."uri-reference"
property $schema
$schema?: string;The
$schemakeyword is both used as a JSON Schema dialect identifier and as the identifier of a resource which is itself a JSON Schema, which describes the set of valid schemas written for this particular dialect.The value of this keyword MUST be a [URI][RFC3986] (containing a scheme) and this URI MUST be normalized. The current schema MUST be valid against the meta-schema identified by this URI.
If this URI identifies a retrievable resource, that resource SHOULD be of media type
application/schema+json.The
$schemakeyword SHOULD be used in the document root schema object, and MAY be used in the root schema objects of embedded schema resources. It MUST NOT appear in non-resource root schema objects. If absent from the document root schema, the resulting behavior is implementation-defined.Values for this property are defined elsewhere in this and other documents, and by other parties.
[RFC3986]: https://datatracker.ietf.org/doc/html/rfc3986
"uri"
property $vocabulary
$vocabulary?: Record<string, boolean>;The
$vocabularykeyword is used in meta-schemas to identify the vocabularies available for use in schemas described by that meta-schema. It is also used to indicate whether each vocabulary is required or optional, in the sense that an implementation MUST understand the required vocabularies in order to successfully process the schema. Together, this information forms a dialect. Any vocabulary that is understood by the implementation MUST be processed in a manner consistent with the semantic definitions contained within the vocabulary.The value of this keyword MUST be an object. The property names in the object MUST be URIs (containing a scheme) and this URI MUST be normalized. Each URI that appears as a property name identifies a specific set of keywords and their semantics.
The URI MAY be a URL, but the nature of the retrievable resource is currently undefined, and reserved for future use. Vocabulary authors MAY use the URL of the vocabulary specification, in a human-readable media type such as
text/htmlortext/plain, as the vocabulary URI.The values of the object properties MUST be booleans. If the value is
true, then implementations that do not recognize the vocabulary MUST refuse to process any schemas that declare this meta-schema with$schema. If the value isfalse, implementations that do not recognize the vocabulary SHOULD proceed with processing such schemas. The value has no impact if the implementation understands the vocabulary.Unrecognized keywords SHOULD be ignored. This remains the case for keywords defined by unrecognized vocabularies. It is not currently possible to distinguish between unrecognized keywords that are defined in vocabularies from those that are not part of any vocabulary.
The
$vocabularykeyword SHOULD be used in the root schema of any schema document intended for use as a meta-schema. It MUST NOT appear in subschemas.The
$vocabularykeyword MUST be ignored in schema documents that are not being processed as a meta-schema.
property additionalItems
additionalItems?: Sub;Deprecated
additionalItemshas been deprecated in favor ofprefixItemspaired withitems.
property additionalProperties
additionalProperties?: Sub;The value of
additionalPropertiesMUST be a valid JSON Schema.The behavior of this keyword depends on the presence and annotation results of
propertiesandpatternPropertieswithin the same schema object. Validation withadditionalPropertiesapplies only to the child values of instance names that do not appear in the annotation results of eitherpropertiesorpatternProperties.For all such properties, validation succeeds if the child instance validates against the
additionalPropertiesschema.The annotation result of this keyword is the set of instance property names validated by this keyword's subschema. Annotation results for
additionalPropertieskeywords from multiple schemas applied to the same instance location are combined by taking the union of the sets. This annotation affects the behavior ofunevaluatedPropertiesin the Unevaluated vocabulary.Omitting this keyword has the same assertion behavior as an empty schema.
Implementations MAY choose to implement or optimize this keyword in another way that produces the same effect, such as by directly checking the names in
propertiesand the patterns inpatternPropertiesagainst the instance property set.
property allOf
allOf?: MaybeReadonlyArray<Sub>;This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword's value.
property anyOf
anyOf?: MaybeReadonlyArray<Sub>;This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
An instance validates successfully against this keyword if it validates successfully against at least one schema defined by this keyword's value.
property const
const?: Value;An instance validates successfully against this keyword if its value is equal to the value of the keyword.
Use of this keyword is functionally equivalent to the
enumkeyword with a single value.
property contains
contains?: Sub;The value of this keyword MUST be a valid JSON Schema.
An array instance is valid against
containsif at least one of its elements is valid against the given schema, except whenminContainsis present and has a value of0, in which case an array instance MUST be considered valid against thecontainskeyword, even if none of its elements is valid against the given schema.This keyword produces an annotation value which is an array of the indexes to which this keyword validates successfully when applying its subschema, in ascending order. The value MAY be a boolean
trueif the subschema validates successfully when applied to every index of the instance. The annotation MUST be present if the instance array to which this keyword's schema applies is empty.This annotation affects the behavior of
unevaluatedItemsin the Unevaluated vocabulary, and MAY also be used to implement theminContainsandmaxContainskeywords in the Validation vocabulary.The subschema MUST be applied to every array element even after the first match has been found, in order to collect annotations for use by other keywords. This is to ensure that all possible annotations are collected.
property contentEncoding
contentEncoding?: string;If the instance value is a string, this property defines that the string SHOULD be interpreted as encoded binary data and decoded using the encoding named by this property.
Possible values indicating base 16, 32, and 64 encodings with several variations are listed in [RFC 4648][RFC4648]. Additionally, sections 6.7 and 6.8 of [RFC 2045][RFC2045] provide encodings used in MIME. This keyword is derived from MIME's Content-Transfer-Encoding header, which was designed to map binary data into ASCII characters. It is not related to HTTP's Content-Encoding header, which is used to encode (e.g. compress or encrypt) the content of HTTP request and responses.
As
"base64"is defined in both RFCs, the definition from RFC 4648 SHOULD be assumed unless the string is specifically intended for use in a MIME context. Note that all of these encodings result in strings consisting only of 7-bit ASCII characters. Therefore, this keyword has no meaning for strings containing characters outside of that range.If this keyword is absent, but
contentMediaTypeis present, this indicates that the encoding is the identity encoding, meaning that no transformation was needed in order to represent the content in a UTF-8 string.The value of this property MUST be a string.
The
ContentEncodingenum lists the well-known values.[RFC2045]: https://datatracker.ietf.org/doc/html/rfc2045#section-6.7 [RFC4648]: https://datatracker.ietf.org/doc/html/rfc4648
property contentMediaType
contentMediaType?: string;If the instance is a string, this property indicates the media type of the contents of the string. If
contentEncodingis present, this property describes the decoded string.The value of this property must be a media type, as defined by [RFC 2046][RFC2046]. This property defines the media type of instances which this schema defines.
The value of this property SHOULD be ignored if the instance described is not a string.
If the
contentEncodingproperty is not present, but the instance value is a string, then the value of this property SHOULD specify a text document type, and the character set SHOULD be the character set into which the JSON string value was decoded (for which the default is Unicode).[RFC2046]: https://datatracker.ietf.org/doc/html/rfc2046
property contentSchema
contentSchema?: Sub;If the instance is a string, and if
contentMediaTypeis present, this property contains a schema which describes the structure of the string.This keyword MAY be used with any media type that can be mapped into JSON Schema's data model.
The value of this property MUST be a valid JSON schema. It SHOULD be ignored if
contentMediaTypeis not present.
property default
default?: Value;This keyword can be used to supply a default JSON value associated with a particular schema. It is RECOMMENDED that a
defaultvalue be valid against the associated schema.
property definitions
definitions?: Record<string, Sub>;Deprecated
definitionshas been renamed to$defs.
property dependencies
dependencies?: Record<string, MaybeReadonlyArray<string> | Sub>;Deprecated
dependencieshas been split into two keywords:dependentSchemasanddependentRequired.
property dependentRequired
dependentRequired?: Record<string, MaybeReadonlyArray<string>>;The value of this keyword MUST be an object. Properties in this object, if any, MUST be arrays. Elements in each array, if any, MUST be strings, and MUST be unique.
This keyword specifies properties that are required if a specific other property is present. Their requirement is dependent on the presence of the other property.
Validation succeeds if, for each name that appears in both the instance and as a name within this keyword's value, every item in the corresponding array is also the name of a property in the instance.
Omitting this keyword has the same behavior as an empty object.
property dependentSchemas
dependentSchemas?: Record<string, Sub>;This keyword specifies subschemas that are evaluated if the instance is an object and contains a certain property.
This keyword's value MUST be an object. Each value in the object MUST be a valid JSON Schema.
If the object key is a property in the instance, the entire instance must validate against the subschema. Its use is dependent on the presence of the property.
Omitting this keyword has the same behavior as an empty object.
property deprecated
deprecated?: boolean;The value of this keyword MUST be a boolean. When multiple occurrences of this keyword are applicable to a single sub-instance, applications SHOULD consider the instance location to be deprecated if any occurrence specifies a
truevalue.If
deprecatedhas a value of booleantrue, it indicates that applications SHOULD refrain from usage of the declared property. It MAY mean the property is going to be removed in the future.A root schema containing
deprecatedwith a value oftrueindicates that the entire resource being described MAY be removed in the future.The
deprecatedkeyword applies to each instance location to which the schema object containing the keyword successfully applies. This can result in scenarios where every array item or object property is deprecated even though the containing array or object is not.Omitting this keyword has the same behavior as a value of
false.false
property description
description?: string;Can be used to decorate a user interface with explanation or information about the data produced.
property else
else?: Sub;This keyword's value MUST be a valid JSON Schema.
When
ifis present, and the instance fails to validate against its subschema, then validation succeeds against this keyword if the instance successfully validates against this keyword's subschema.This keyword has no effect when
ifis absent, or when the instance successfully validates against its subschema. Implementations MUST NOT evaluate the instance against this keyword, for either validation or annotation collection purposes, in such cases.
property enum
enum?: MaybeReadonlyArray<Value>;The value of this keyword MUST be an array. This array SHOULD have at least one element. Elements in the array SHOULD be unique.
An instance validates successfully against this keyword if its value is equal to one of the elements in this keyword's array value.
Elements in the array might be of any type, including
null.
property examples
examples?: MaybeReadonlyArray<Value>;The value of this keyword MUST be an array. When multiple occurrences of this keyword are applicable to a single sub-instance, implementations MUST provide a flat array of all values rather than an array of arrays.
This keyword can be used to provide sample JSON values associated with a particular schema, for the purpose of illustrating usage. It is RECOMMENDED that these values be valid against the associated schema.
Implementations MAY use the value(s) of
default, if present, as an additional example. Ifexamplesis absent,defaultMAY still be used in this manner.
property exclusiveMaximum
exclusiveMaximum?: number;The value of
exclusiveMaximumMUST be a number, representing an exclusive upper limit for a numeric instance.If the instance is a number, then the instance is valid only if it has a value strictly less than (not equal to)
exclusiveMaximum.
property exclusiveMinimum
exclusiveMinimum?: number;The value of
exclusiveMinimumMUST be a number, representing an exclusive lower limit for a numeric instance.If the instance is a number, then the instance is valid only if it has a value strictly greater than (not equal to)
exclusiveMinimum.
property format
format?: string;Implementations MAY treat
formatas an assertion in addition to an annotation, and attempt to validate the value's conformance to the specified semantics.The value of this keyword is called a format attribute. It MUST be a string. A format attribute can generally only validate a given set of instance types. If the type of the instance to validate is not in this set, validation for this format attribute and instance SHOULD succeed. Format attributes are most often applied to strings, but can be specified to apply to any type.
Implementations MAY support custom format attributes. Save for agreement between parties, schema authors SHALL NOT expect a peer implementation to support such custom format attributes. An implementation MUST NOT fail validation or cease processing due to an unknown format attribute. When treating
formatas an annotation, implementations SHOULD collect both known and unknown format attribute values.
property if
if?: Sub;This keyword's value MUST be a valid JSON Schema.
This validation outcome of this keyword's subschema has no direct effect on the overall validation result. Rather, it controls which of the
thenorelsekeywords are evaluated.Instances that successfully validate against this keyword's subschema MUST also be valid against the subschema value of the
thenkeyword, if present.Instances that fail to validate against this keyword's subschema MUST also be valid against the subschema value of the
elsekeyword, if present.If annotations are being collected, they are collected from this keyword's subschema in the usual way, including when the keyword is present without either
thenorelse.
property items
items?: Sub;The value of
itemsMUST be a valid JSON Schema.This keyword applies its subschema to all instance elements at indexes greater than the length of the
prefixItemsarray in the same schema object, as reported by the annotation result of thatprefixItemskeyword. If no such annotation result exists,itemsapplies its subschema to all instance array elements.Note that the behavior of
itemswithoutprefixItemsis identical to that of the schema form ofitemsin prior drafts.When
prefixItemsis present, the behavior ofitemsis identical to the formeradditionalItemskeyword.If the
itemssubschema is applied to any positions within the instance array, it produces an annotation result of booleantrue, indicating that all remaining array elements have been evaluated against this keyword's subschema. This annotation affects the behavior ofunevaluatedItemsin the Unevaluated vocabulary.Omitting this keyword has the same assertion behavior as an empty schema.
Implementations MAY choose to implement or optimize this keyword in another way that produces the same effect, such as by directly checking for the presence and size of a
prefixItemsarray.
property maxContains
maxContains?: number;The value of this keyword MUST be a non-negative integer.
If
containsis not present within the same schema object, then this keyword has no effect.An instance array is valid against
maxContainsin two ways, depending on the form of the annotation result of an adjacentcontainskeyword. The first way is if the annotation result is an array and the length of that array is less than or equal to themaxContainsvalue. The second way is if the annotation result is a booleantrueand the instance array length is less than or equal to themaxContainsvalue.0
property maximum
maximum?: number;The value of
maximumMUST be a number, representing an inclusive upper limit for a numeric instance.If the instance is a number, then this keyword validates only if the instance is less than or exactly equal to
maximum.
property maxItems
maxItems?: number;The value of this keyword MUST be a non-negative integer.
An array instance is valid against
maxItemsif its size is less than, or equal to, the value of this keyword.0
property maxLength
maxLength?: number;The value of this keyword MUST be a non-negative integer.
A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.
The length of a string instance is defined as the number of its characters as defined by [RFC 8259][RFC8259].
[RFC8259]: https://datatracker.ietf.org/doc/html/rfc8259
0
property maxProperties
maxProperties?: number;The value of this keyword MUST be a non-negative integer.
An object instance is valid against
maxPropertiesif its number ofpropertiesis less than, or equal to, the value of this keyword.0
property minContains
minContains?: number;The value of this keyword MUST be a non-negative integer.
If
containsis not present within the same schema object, then this keyword has no effect.An instance array is valid against
minContainsin two ways, depending on the form of the annotation result of an adjacentcontainskeyword. The first way is if the annotation result is an array and the length of that array is greater than or equal to theminContainsvalue. The second way is if the annotation result is a booleantrueand the instance array length is greater than or equal to theminContainsvalue.A value of
0is allowed, but is only useful for setting a range of occurrences from0to the value ofmaxContains. A value of0causesminContainsandcontainsto always pass validation (but validation can still fail against amaxContainskeyword).Omitting this keyword has the same behavior as a value of
1.1 0
property minimum
minimum?: number;The value of
minimumMUST be a number, representing an inclusive lower limit for a numeric instance.If the instance is a number, then this keyword validates only if the instance is greater than or exactly equal to
minimum.
property minItems
minItems?: number;The value of this keyword MUST be a non-negative integer.
An array instance is valid against
minItemsif its size is greater than, or equal to, the value of this keyword.Omitting this keyword has the same behavior as a value of
0.0 0
property minLength
minLength?: number;The value of this keyword MUST be a non-negative integer.
A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
The length of a string instance is defined as the number of its characters as defined by [RFC 8259][RFC8259].
Omitting this keyword has the same behavior as a value of
0.[RFC8259]: https://datatracker.ietf.org/doc/html/rfc8259
0 0
property minProperties
minProperties?: number;The value of this keyword MUST be a non-negative integer.
An object instance is valid against
minPropertiesif its number ofpropertiesis greater than, or equal to, the value of this keyword.Omitting this keyword has the same behavior as a value of
0.0 0
property multipleOf
multipleOf?: number;The value of
multipleOfMUST be a number, strictly greater than0.A numeric instance is valid only if division by this keyword's value results in an integer.
0
property not
not?: Sub;This keyword's value MUST be a valid JSON Schema.
An instance is valid against this keyword if it fails to validate successfully against the schema defined by this keyword.
property oneOf
oneOf?: MaybeReadonlyArray<Sub>;This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
An instance validates successfully against this keyword if it validates successfully against exactly one schema defined by this keyword's value.
property pattern
pattern?: string;The value of this keyword MUST be a string. This string SHOULD be a valid regular expression, according to the [ECMA-262][ecma262] regular expression dialect.
A string instance is considered valid if the regular expression matches the instance successfully. Recall: regular expressions are not implicitly anchored.
[ecma262]: https://www.ecma-international.org/publications-and-standards/standards/ecma-262/
"regex"
property patternProperties
patternProperties?: Record<string, Sub>;The value of
patternPropertiesMUST be an object. Each property name of this object SHOULD be a valid regular expression, according to the [ECMA-262][ecma262] regular expression dialect. Each property value of this object MUST be a valid JSON Schema.Validation succeeds if, for each instance name that matches any regular expressions that appear as a property name in this keyword's value, the child instance for that name successfully validates against each schema that corresponds to a matching regular expression.
The annotation result of this keyword is the set of instance property names matched by this keyword. This annotation affects the behavior of
additionalProperties(in this vocabulary) andunevaluatedProperties(in the Unevaluated vocabulary). Omitting this keyword has the same assertion behavior as an empty object.[ecma262]: https://www.ecma-international.org/publications-and-standards/standards/ecma-262/
property prefixItems
prefixItems?: MaybeReadonlyArray<Sub>;The value of
prefixItemsMUST be a non-empty array of valid JSON Schemas.Validation succeeds if each element of the instance validates against the schema at the same position, if any. This keyword does not constrain the length of the array. If the array is longer than this keyword's value, this keyword validates only the prefix of matching length.
This keyword produces an annotation value which is the largest index to which this keyword applied a subschema. The value MAY be a boolean
trueif a subschema was applied to every index of the instance, such as is produced by theitemskeyword. This annotation affects the behavior ofitemsandunevaluatedItems.Omitting this keyword has the same assertion behavior as an empty array.
property properties
properties?: Record<string, Sub>;The value of
propertiesMUST be an object. Each value of this object MUST be a valid JSON Schema.Validation succeeds if, for each name that appears in both the instance and as a name within this keyword's value, the child instance for that name successfully validates against the corresponding schema.
The annotation result of this keyword is the set of instance property names matched by this keyword. This annotation affects the behavior of
additionalProperties(in this vocabulary) andunevaluatedPropertiesin the Unevaluated vocabulary.Omitting this keyword has the same assertion behavior as an empty object.
property propertyNames
propertyNames?: Sub;The value of
propertyNamesMUST be a valid JSON Schema.If the instance is an object, this keyword validates if every property name in the instance validates against the provided schema. Note the property name that the schema is testing will always be a string.
Omitting this keyword has the same behavior as an empty schema.
property readOnly
readOnly?: boolean;The value of this keyword MUST be a boolean. When multiple occurrences of this keyword are applicable to a single sub-instance, the resulting value MUST be
trueif any occurrence specifies atruevalue, and MUST befalseotherwise.If
readOnlyhas a value of booleantrue, it indicates that the value of the instance is managed exclusively by the owning authority, and attempts by an application to modify the value of this property are expected to be ignored or rejected by that owning authority.An instance document that is marked as
readOnlyfor the entire document MAY be ignored if sent to the owning authority, or MAY result in an error, at the authority's discretion.For example,
readOnlywould be used to mark a database-generated serial number as read-only.This keyword can be used to assist in user interface instance generation.
false
property required
required?: MaybeReadonlyArray<string>;The value of this keyword MUST be an array. Elements of this array, if any, MUST be strings, and MUST be unique.
An object instance is valid against this keyword if every item in the array is the name of a property in the instance.
Omitting this keyword has the same behavior as an empty array.
property then
then?: Sub;This keyword's value MUST be a valid JSON Schema.
When
ifis present, and the instance successfully validates against its subschema, then validation succeeds against this keyword if the instance also successfully validates against this keyword's subschema.This keyword has no effect when
ifis absent, or when the instance fails to validate against its subschema. Implementations MUST NOT evaluate the instance against this keyword, for either validation or annotation collection purposes, in such cases.
property title
title?: string;Can be used to decorate a user interface with a short label about the data produced.
property type
type?: SchemaType;The value of this keyword MUST be either a string or an array. If it is an array, elements of the array MUST be strings and MUST be unique.
String values MUST be one of the six primitive types (
"null","boolean","object","array","number", or"string"), or"integer"which matches any number with a zero fractional part.If the value of
typeis a string, then an instance validates successfully if its type matches the type represented by the value of the string.If the value of
typeis an array, then an instance validates successfully if its type matches any of the types indicated by the strings in the array.
property unevaluatedItems
unevaluatedItems?: Sub;The value of
unevaluatedItemsMUST be a valid JSON Schema.The behavior of this keyword depends on the annotation results of adjacent keywords that apply to the instance location being validated. Specifically, the annotations from
prefixItems,items, andcontains, which can come from those keywords when they are adjacent to theunevaluatedItemskeyword. Those three annotations, as well asunevaluatedItems, can also result from any and all adjacent [in-place applicator][in-place-applicator] keywords.If no relevant annotations are present, the
unevaluatedItemssubschema MUST be applied to all locations in the array. If a booleantruevalue is present from any of the relevant annotations,unevaluatedItemsMUST be ignored. Otherwise, the subschema MUST be applied to any index greater than the largest annotation value forprefixItems, which does not appear in any annotation value forcontains.This means that
prefixItems,items,contains, and all in-place applicators MUST be evaluated before this keyword can be evaluated. Authors of extension keywords MUST NOT define an in-place applicator that would need to be evaluated after this keyword.If the
unevaluatedItemssubschema is applied to any positions within the instance array, it produces an annotation result of booleantrue, analogous to the behavior ofitems. This annotation affects the behavior ofunevaluatedItemsin parent schemas.Omitting this keyword has the same assertion behavior as an empty schema.
[in-place-applicator]: https://json-schema.org/draft/2020-12/json-schema-core.html#in-place
property unevaluatedProperties
unevaluatedProperties?: Sub;The value of
unevaluatedPropertiesMUST be a valid JSON Schema.The behavior of this keyword depends on the annotation results of adjacent keywords that apply to the instance location being validated. Specifically, the annotations from
properties,patternProperties, andadditionalProperties, which can come from those keywords when they are adjacent to theunevaluatedPropertieskeyword. Those three annotations, as well asunevaluatedProperties, can also result from any and all adjacent [in-place applicator][in-place-applicator] keywords.Validation with
unevaluatedPropertiesapplies only to the child values of instance names that do not appear in theproperties,patternProperties,additionalProperties, orunevaluatedPropertiesannotation results that apply to the instance location being validated.For all such properties, validation succeeds if the child instance validates against the "unevaluatedProperties" schema.
This means that
properties,patternProperties,additionalProperties, and all in-place applicators MUST be evaluated before this keyword can be evaluated. Authors of extension keywords MUST NOT define an in-place applicator that would need to be evaluated after this keyword.The annotation result of this keyword is the set of instance property names validated by this keyword's subschema. This annotation affects the behavior of
unevaluatedPropertiesin parent schemas.Omitting this keyword has the same assertion behavior as an empty schema.
[in-place-applicator]: https://json-schema.org/draft/2020-12/json-schema-core.html#in-place
property uniqueItems
uniqueItems?: boolean;The value of this keyword MUST be a boolean.
If this keyword has boolean value
false, the instance validates successfully. If it has boolean valuetrue, the instance validates successfully if all of its elements are unique.Omitting this keyword has the same behavior as a value of
false.false
property writeOnly
writeOnly?: boolean;The value of this keyword MUST be a boolean. When multiple occurrences of this keyword is applicable to a single sub-instance, the resulting value MUST be
trueif any occurrence specifies atruevalue, and MUST befalseotherwise.If
writeOnlyhas a value of booleantrue, it indicates that the value is never present when the instance is retrieved from the owning authority. It can be present when sent to the owning authority to update or create the document (or the resource it represents), but it will not be included in any updated or newly created version of the instance.An instance document that is marked as
writeOnlyfor the entire document MAY be returned as a blank document of some sort, or MAY produce an error upon retrieval, or have the retrieval request ignored, at the authority's discretion.For example,
writeOnlywould be used to mark a password input field.These keywords can be used to assist in user interface instance generation. In particular, an application MAY choose to use a widget that hides input values as they are typed for write-only fields.
false
type Array
type Array<T = any> = Narrowed<T, 'array'>;type Boolean
type Boolean = Narrowed<boolean, 'boolean'>;type Integer
type Integer = Narrowed<number, 'integer'>;type KeywordsFor
type KeywordsFor<SchemaType extends TypeValue> = | KeywordByType.Any | (SchemaType extends 'array' ? KeywordByType.Array : never) | (SchemaType extends 'integer' | 'number' ? KeywordByType.Number : never) | (SchemaType extends 'object' ? KeywordByType.Object : never) | (SchemaType extends 'string' ? KeywordByType.String : never) | (SchemaType extends MaybeReadonlyArray<unknown> ? keyof Interface : never);The keywords permitted for a given
typevalue. Keywords shared by every type are always included; type-specific keywords are included whenSchemaTypecontains that type. A list of type names permits the keywords of every type in the list.
type Narrowed
type Narrowed<Value, SchemaType extends TypeValue, Sub = JSONSchema> = Pick< Interface<Value, SchemaType, Sub>, KeywordsFor<SchemaType>>;A schema object with only the keywords that apply to
SchemaType.JSONSchema.String,JSONSchema.Object, etc. are instances of this.
type Null
type Null = Narrowed<null, 'null'>;type Number
type Number = Narrowed<number, 'number'>;type Object
type Object<T = any> = Narrowed<T, 'object'>;type String
type String = Narrowed<string, 'string'>;type TypeValue
type TypeValue = | TypeName | `${TypeName}` | MaybeReadonlyArray<TypeName | `${TypeName}`>;Every value the
typekeyword accepts: a single type name (as a string literal or aTypeNameenum member) or a list of them.
namespace KeywordByType
namespace KeywordByType {}Keyword names grouped by the
typethey apply to.Anyapplies to every type.
type Any
type Any = | '$anchor' | '$comment' | '$defs' | '$dynamicAnchor' | '$dynamicRef' | '$id' | '$recursiveAnchor' | '$recursiveRef' | '$ref' | '$schema' | '$vocabulary' | 'allOf' | 'anyOf' | 'const' | 'default' | 'definitions' | 'deprecated' | 'description' | 'else' | 'enum' | 'examples' | 'format' | 'if' | 'not' | 'oneOf' | 'readOnly' | 'then' | 'title' | 'type' | 'writeOnly';type Array
type Array = | 'additionalItems' | 'contains' | 'items' | 'maxContains' | 'maxItems' | 'minContains' | 'minItems' | 'prefixItems' | 'unevaluatedItems' | 'uniqueItems';type Number
type Number = | 'exclusiveMaximum' | 'exclusiveMinimum' | 'maximum' | 'minimum' | 'multipleOf';type Object
type Object = | 'additionalProperties' | 'dependencies' | 'dependentRequired' | 'dependentSchemas' | 'maxProperties' | 'minProperties' | 'patternProperties' | 'properties' | 'propertyNames' | 'required' | 'unevaluatedProperties';type String
type String = | 'contentEncoding' | 'contentMediaType' | 'contentSchema' | 'maxLength' | 'minLength' | 'pattern';Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (4)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/json-schema-typed.
- Markdown[](https://www.jsdocs.io/package/json-schema-typed)
- HTML<a href="https://www.jsdocs.io/package/json-schema-typed"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2896 ms. - Missing or incorrect documentation? Open an issue for this package.
