Reputation: 137
I want to restrict my application to only support "string" type values for json configuration. Json schema by default supports a set of datatypes such as integer, boolean, etc however, the parsing logic in my application only supports string values.
How do I make sure the schema does not define a property of any type except string.
Allow - { "key1": "A", "key2": "B" }
Reject - { "key1": "A", "key2": true} or { "key1": "A", "key2": ["1","2"]}
Upvotes: 0
Views: 99
Reputation: 3219
This would be the most basic example to match your requirements. Each property
defines a type
(data type). This type
keyword is the constraint applied to that property
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "a basic schema",
"type": "object",
"properties": {
"key1": {
"type": "string"
},
"key2": {
"type": "string"
}
}
}
Take a look at this fundamentals post from the JSON Schema blog for a nice introduction to understanding JSON Schema.
Upvotes: 0