Altova XMLSpy 2024 Enterprise Edition

Type Selectors (Any, Multiple, etc)

Home Prev Top Next

In the dropdown lists of the Type combo boxes of JSON Schema View, there are four "types" that are not JSON types: any, multiple, unconstrained, and forbidden. These are actually type selectors.

 

The any type selector selects any JSON type. This means that, in the instance, any JSON type will be valid for that particular definition.

The multiple type selector selects one or more JSON types. This means that if the instance type is one of the JSON types selected in the schema, then the instance type will be valid for that particular definition.

The unconstrained type selector (new in draft-06) sets no constraint on the JSON type. This means that, in the instance, any JSON type will be valid for a definition with that name.

The forbidden type selector (new in draft-06) forbids any JSON type, effectively not allowing a definition with that name to exist.

 

The any type selector

The any type selector can be selected everywhere that a type can be selected. When a definition is added to the schema, any is the default type selection. It specifies that any of the JSON types is valid. This means that the instance type could validly be an object, an array, or any of the atomic types (string, number, integer, boolean, and null).

JSONAny01

In the screenshot above, the sub-schema has a type of Any. So, all JSON types are valid for this definition. The following is implied and is implemented accordingly in the UI:

 

Since objects are allowed, a properties box is automatically created (see screenshot above). The properties box is defined by default to allow any number of properties of any type (via a property wildcard with a type of Any). You can modify the property definitions as you like.

Since arrays are allowed, an items box is automatically created (see screenshot above). The array items box is defined by default to allow any number of array items of any type (via an array item wildcard with a type of Any). You can modify the item definitions as you like.

Since string and numeric (number and integer) types are allowed, constraints for these atomic types can be defined in the Constraints entry helper.

 

All of these types are therefore implicitly defined with the Any type selector. In order to change the type to a specific type, select that type. There is an alternative way to specify objects and arrays as the type: Right-click the object or array, and select Make Explicit. This makes that type the selected type and removes the other types or makes defined object/array types inactive.

 

The multiple type selector

The multiple type selector can be selected everywhere that a type can be selected. It allows you to select one or more JSON types by checking the types you want to allow (see screenshot below). You can then specify constraints for the selected types in the Constraints entry helper.

JSONMultiple01

In the screenshot above, the sub-schema allows types of string, null, and array. Constraints for these types can be defined in the Constraints entry helper (see screenshot).

 

String constraints are defined in the Constraints entry helper.

The null type takes no further constraints.

An array items box is automatically created. You can define the number and types of allowed array items.

 

In an instance document, the selected types will be allowed at the location corresponding to that of the sub-schema.

 

The unconstrained and forbidden type selectors

The unconstrained and forbidden type selectors can be selected everywhere that a type can be selected. They enable you to specify, respectively, that an object  of any type is allowed or that no object of that name is allowed.

JSONUnconstrainedForbidden

In the screenshot above, a definition has two properties. PropertyOne can have a value of any type, whereas no property named PropertyTwo is allowed (see screenshot). In text form, this construct will look like the code listing below.

 

"Definition": {

 "properties": {

         "PropertyOne": true,

         "PropertyTwo": false

 }

}

 

 

© 2017-2023 Altova GmbH