Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define property of type percentage in Json Schema 4

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" }
like image 294
Hussain ali Avatar asked Nov 18 '16 09:11

Hussain ali


People also ask

How does JSON define decimal?

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.

What is JSON Schema properties?

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”.

What does Exclusiveminimum property in JSON Schema mean?

Gets or sets a flag indicating whether the value can not equal the number defined by the minimum attribute (Minimum).


1 Answers

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)

like image 86
Pedro Avatar answered Sep 23 '22 14:09

Pedro