I am designing a Json schema and I want to show percentage. I am not sure which type i should select to define percentage in Json schema. any help would be appreciated.
"rate": { "type": "percentage" }
JSON does not have distinct types for integers and floating-point values. Therefore, the presence or absence of a decimal point is not enough to distinguish between integers and non-integers. For example, 1 and 1.0 are two ways to represent the same value in JSON.
Objects are the mapping type in JSON. They map “keys” to “values”. In JSON, the “keys” must always be strings. Each of these pairs is conventionally referred to as a “property”.
Gets or sets a flag indicating whether the value can not equal the number defined by the minimum attribute (Minimum).
There is no percentage type in json schema.
You could do this:
{
"type": "number",
"minimum": 0,
"maximum": 1,
}
and use the fraction.
Or if you want to use numbers between 0 and 100:
{
"type": "number",
"minimum": 0,
"maximum": 100,
}
Also, you could add the "multipleOf" keyword to specify how much decimals you want. For example "multipleOf: 0.1" (for 1 decimal) or "multiplpeOf: 0.01" (for 2 decimals)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With