JSON Schema

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  User Guide and Reference > JSON, JSON Schema >

JSON Schema

In the same way that an XML Schema specifies the structure and content of an XML document, a JSON schema specifies how the JSON data in a JSON document is organized. It specifies what data fields are expected and how the values are represented. The JSON Schema specification and more information about JSON Schema is available here.


A JSON schema is itself a JSON object. Lexically, the entire schema is contained within curly braces (see listing below), which are the delimiters of JSON objects. The schema is written in JSON syntax and will be saved typically in a file with a .json extension. It is indicated as a JSON schema, by the $schema keyword, which should be the first keyword of the top-level object, and should have the value: "http://json-schema.org/draft-04/schema#". (The $schema keyword is optional but recommended, and can occur anywhere within the top-level object.)



   "$schema": "http://json-schema.org/draft-04/schema#",




Note:Although the $schema keyword can have the value "http://json-schema.org/schema#"—which specifies the latest version of the schema—it is best to use a URL that identifies the specific version, currently: "http://json-schema.org/draft-04/schema#".



In XMLSpy, you can create JSON schemas graphically in JSON Schema View. How to do this is described in the section JSON Schema View. Besides the schema editing features available in JSON Schema View, the following schema-related features are available:


Validation with the JSON Validator of XMLSpy: Assign a JSON schema to a JSON instance document, and validate the instance document from within XMLSpy. See Validating JSON Documents for information.
Generating JSON Schema from a JSON Instance: If a JSON instance document already exists, you can generate a JSON schema from it. You can subsequently edit the schema if you need to.
Converting between JSON and XML: You can convert between documents of the two formats.



Given below are definitions of common JSON schema terms used in the GUI and this documentation.





The top-level schema object in a JSON schema document; the schema file.


A JSON type containing zero or more properties.


A key:value pair of an object. Its value can be any JSON datatype.


The key part of an object's key:value pair. It is always a string.


An object that is a child of an operator or a dependency.


The complete description of any JSON type. Definitions can be global or local.


A comma-separated ordered list of zero or more items of any JSON datatype.

Atomic types

The string, number, integer, boolean, and null JSON datatypes.

Type selectors

The any and multiple types, which select any and multiple types, respectively


Occurrence selectors that can be added as children of definitions. See the section Operators.


JSON data types

Object property values and array items can be of the following types:


string (must be enclosed in quotes). A string can additionally be specified to have a format, such as a date-time or email format
number: A number with a fractional part; it includes integers
integer: A number with no fractional part; a subset of the number type
boolean (true/false, not enclosed in quotes)
object: When used within another object, allows data to be nested
array: Provides the ability to build more complex structures than allowed by objects
null (null, not enclosed in quotes)


© 2018 Altova GmbH