JSON Schema
An Introduction
Prof. David Bernstein
James Madison University
Computer Science Department
bernstdh@jmu.edu
Review
JSON
:
A syntax for describing hierarchical data
A Shortcoming:
A document can be syntactically correct but not contain the correct elements
Objectives
Impose Structure:
For validation, documentation and interaction control
Syntax:
Use JSON
Some Common Keywords and Allowed Values
"title"
A string
"type"
"null", "boolean", "object", "array", "number", or "string"
"required"
An array
"properties"
An object
"items"
A schema or array of schemas
An Example
A Schema for a Simple
Person
jsonexamples/schema/person.jsonschema
Some Other Keywords
For Numbers:
maximum, minimum, multipleOf
For Strings:
maxLength, minLength, pattern
For Arrays:
items, maxItems, minItems, uniqueItems, contains
For Objects:
maxProperties, minProperties
There's Always More to Learn