Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JSON-schema
{
"$schema": "./drivers.schema.json",
"series": "f1",
"season": 2018,
"driverList": [
{
"raceNumber": 14,
"code": "ALO",
"firstName": "Fernando",
"lastName": "Alonso",
"dateOfBirth": "1981-07-29",
"team": "MCLAREN",
"quotes": ["GP2 engine, GP2", "5 second penalty? Issa yoke"]
},
{
"raceNumber": 3,
"code": "RIC",
"firstName": "Daniel",
"lastName": "Ricciardo",
"dateOfBirth": "1989-07-01",
"nationality": "Australian",
"team": "REDBULL"
}
]
}
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Drivers",
"description": "Formula 1 drivers",
"type": "object",
"additionalProperties": false,
"properties": {
"$schema": {
"type": "string",
"description": "path to the JSON-schema to use for this file"
},
"series": {
"type": "string",
"const": "f1"
},
"season": {
"type": "integer",
"description": "year corresponding with season"
},
"driverList": {
"type": "array",
"items": {
"$ref": "#/definitions/driver"
}
}
},
"definitions": {
"driver": {
"type": "object",
"additionalProperties": false,
"properties": {
"raceNumber": {
"type": "integer",
"minimum": 0,
"maximum": 99,
"description": "number this driver races with"
},
"code": {
"type": "string",
"minLength": 3,
"maxLength": 3,
"description": "3 letter abbreviation"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"dateOfBirth": {
"type": "string",
"format": "date",
"description": "dateOfBirth in YYYY-MM-DD format",
"default": "YYYY-MM-DD"
},
"nationality": {
"type": "string"
},
"team": {
"$ref": "#/definitions/team"
},
"quotes": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
}
},
"required": ["raceNumber", "code", "team"]
},
"team": {
"enum": [
"MCLAREN",
"FERRARI",
"REDBULL",
"TOROROSSO",
"MERCEDES",
"RENAULT",
"HAAS",
"FORCEINDIA",
"SAUBER",
"WILLIAMS"
]
}
}
}
@averyfreeman
Copy link

averyfreeman commented Jan 21, 2022

Liked the article, thanks for sharing. Is there a resource for a generic list of all the schemas listed at https://schemastore.org so I don't have to populate them all myself, though?

@NickyMeuleman
Copy link
Author

NickyMeuleman commented Jan 21, 2022

Hi @averyfreeman,
Thanks, glad you liked it!
I've noticed a trend recently where many newer tools come with configuration files that use a JSON-schema automatically, no user intervention needed.
As for a way to automatically link the schemas listed on schemastore.org to a .json file in your editor, I don't know. Maybe the folks in the official JSON-schema slack chat know more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment