Support for coercing data types #5824
-
Hello, I was wondering if there is any support or plans to support coercing of data types ? I am referring to the feature that can be seen here for AJV. A scaler value is a I want to validate a thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @alexiskat! Thanks for opening this discussion. We already have the validation utility that can validate input against a JSON schema, but it doesn't support data type coercion before validating it. In this utility we use fastjsonschema, but it also does not support coercion operations before validating the type. Still in this JSON schema space, I was playing around with Cerberus a few months ago and it looks like it supports data coercion before validating, so you can bring it in as a dependency (~300kb) and use it. But, if you want a more robust library to do that, I would suggest to take a look into Pydantic and see if it make sense for your use case. Pydantic supports Data validation and you can coerce types before of after the validation. For now, we have no plans to change the implementation of the Please let me know your thoughts. |
Beta Was this translation helpful? Give feedback.
-
hi @leandrodamascena, I may be missing something but it seem like pretty useful feature to have, especially since the At the moment we really don't want to add another dependency to our lambda. As a work around we are using the following in the schema to validate integer numbers.
thanks |
Beta Was this translation helpful? Give feedback.
Hi @alexiskat! Thanks for opening this discussion.
We already have the validation utility that can validate input against a JSON schema, but it doesn't support data type coercion before validating it. In this utility we use fastjsonschema, but it also does not support coercion operations before validating the type. Still in this JSON schema space, I was playing around with Cerberus a few months ago and it looks like it supports data coercion before validating, so you can bring it in as a dependency (~300kb) and use it.
But, if you want a more robust library to do that, I would suggest to take a look into Pydantic and see if it make sense for your use case. Pydantic supports Data validatio…