Skip to content

Instantly share code, notes, and snippets.

@mscharhag
Created July 21, 2020 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mscharhag/d836dd960fcf9cb35026014447c42e0e to your computer and use it in GitHub Desktop.
Save mscharhag/d836dd960fcf9cb35026014447c42e0e to your computer and use it in GitHub Desktop.
JSON Schema example
// example JSON
{
"name": "Mona Lisa",
"artist": "Leonardo da Vinci",
"description": null,
"dimension": {
"height": 53.0,
"width": 77.0
},
"tags": ["oil", "famous"]
}
// example JSON Schema
{
"$schema": "https://json-schema.org/draft/2019-09/schema#",
"$id": "http://my-paintings-api.com/schemas/painting-schema.json",
"type": "object",
"title": "Painting",
"description": "Painting information",
"additionalProperties": true,
"required": ["name", "artist", "dimension", "description", "tags"],
"properties": {
"name": {
"type": "string",
"description": "Painting name"
},
"artist": {
"type": "string",
"maxLength": 50,
"description": "Name of the artist"
},
"description": {
"type": ["string", "null"],
"description": "Painting description"
},
"dimension": { "$ref": "#/$defs/dimension" },
"tags": {
"type": "array",
"items": { "$ref": "#/$defs/tag" }
}
},
"$defs": {
"tag": {
"type": "string",
"enum": ["oil", "watercolor", "digital", "famous"]
},
"dimension": {
"type": "object",
"title": "Painting dimension",
"description": "Describes the dimension of a painting in cm",
"additionalProperties": true,
"required": ["width", "height"],
"properties": {
"width": { "type": "number", "description": "Width of the product", "minimum": 1 },
"height": { "type": "number", "description": "Height of the product", "minimum": 1 }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment