Created
July 21, 2020 07:30
-
-
Save mscharhag/d836dd960fcf9cb35026014447c42e0e to your computer and use it in GitHub Desktop.
JSON Schema example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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