Hussain ali Hussain ali - 17 days ago 5
JSON Question

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" }

Answer

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)

Comments