Skip to content

Instantly share code, notes, and snippets.

@malcolm-kee
Last active September 11, 2019 10:51
Show Gist options
  • Save malcolm-kee/6161864848889a896f40ec56bc17980e to your computer and use it in GitHub Desktop.
Save malcolm-kee/6161864848889a896f40ec56bc17980e to your computer and use it in GitHub Desktop.
Notes on JSON Schema

To define a schema you should always have type properties, which can be

  • "string"
  • "number" or "integer"
  • "object"
  • "array"
  • "boolean"
  • "null"

type can be a single string or an array of string.

string

If a schema is string, then it can have the following properties as well:

  • minLength
  • maxLength
  • pattern
  • format (e.g. date-time, email, uri)

number or integer

A number could have the following properties:

  • multipleOf
  • minimum
  • maxiumum
  • exclusiveMinimum
  • exclusiveMaximum

object

A object could have the following properties:

  • properties
  • additionalProperties: false indicates properties other than those stated in properties are not allowed.
  • required: an array of string stating the mandatory properties
  • dependencies: could be either of the following
    • an object of {[<this_exists>]: ["then", "these", "are", "required"]}.
    • on object of {[<this_exists>]: <Additional Schema to be Added>}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment