-
-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cast to json schema #683
Comments
Hi. Not sure specifically what you're referring to (technically speaking, Python doesn't have "casting", but I assume you mean creating new dicts. But not sure what it'd mean to cast one to a schema). I assume though you may be looking for something like https://github.com/Julian/Seep/ which was an attempt at what it seems you may mean -- an experimental one that I hoped someone else would pick up and run with, but perhaps it gives you the hints you need. If you're interested in running with it would love to see it, and possibly can even provide some tips (better there than in this repo though). Thanks! |
@Julian def bool_fitter(value):
if isinstance(value, str):
if value.lower() in ["true", "1", "yes"]:
return True
elif value.lower() in ["false", "0", "no"]:
return False
else:
return None
elif isinstance(value, float) or isinstance(value, int):
if value == 0:
return False
elif value == 1:
return True
else:
return None
return None
type_dictionary = {
"string": str,
"number": float_fitter,
"boolean": bool_fitter,
"integer": int_fitter,
} And for float fitter you can handle specific formats such as |
Hi,
Is it possible to implement casting a python dict to a json schema?
Like casting '4' to a number field - yeah, it's a string but can be casted without problems.
I know this is not entirely in the scope of jsonschema's purpose, but if you can give some hints on where to start by extending this project in my own fork that'd be great.
Or is it possible to check instead if the data can be casted successfully to the schema's type? Something like 'loose' validation.
The text was updated successfully, but these errors were encountered: