validation of a Parameter of number type, in jsonschema

Asked

Viewed 34 times

-1

I have a type parameter number and I want to validate the size, how can I do this using the function maximum in a jsonschema?

"type": ["number","null" ], "description": "Maximum Field Length - (23,8)"
  • 1

    Well, it’s not enough to use the maximum as you yourself commented? {"type": "number", "maximum": 20}

  • Hello Anderson, yes I have to use the function Maximum, but I do not know how to implement (23,8) with so much.

  • And what does "(23.8) mean as maximum size"? The value must be less than 23.8?

  • 23 digits and 8 decimal places

2 answers

1


As commented, you want to validate that your number has up to 23 characters in the whole part and 8 characters in the decimal part. You don’t do it with numbers, you do it with strings.

The guy string has the validations minLength, maxLength and pattern:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "price": {
      "type": "string",
      "minLength": 3,
      "maxLength": 32,
      "pattern": "^\\d{1,23}\\.\\d{1,8}$"
    }
  }
}

Thus, the JSON below is valid:

{
  "price": "123.456789"
}

But the JSON below does not, as it has more than 8 characters in the decimal part.

{
  "price": "123.4567890123"
}

-1

I think the best way to validate this would be to input the data with a

if (description.length< maxField)

But I could do so

{
  "type": "string",
  "minLength": 2,
  "maxLength": 3
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.