-
-
Notifications
You must be signed in to change notification settings - Fork 582
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
"array" type should be (list, tuple) #148
Comments
Hey! simplejson will never give you a tuple when loading a JSON array. That said, if you want to actually allow tuples, you can provide a mapping of types that you want to consider to be |
Julian, thank you for you advice, I've figured out with types={'array': (list, tuple)} parameter in .validate() I needed to validate some python dict with nested tuples. |
JSON parsers are not only source for your library. For example I check all requests and all responses. |
Yup -- I'm glad, I think the current APIs should be usable for whatever use case you have in mind, please feel free to reach out if you have any issues. |
Could you please extend |
What is it you mean by extend the array type? As the post two comments above you mentioned, Once again be concrete on where you are having issues. |
Is there a way to do |
Something has apparently changed and using >>> Draft4Validator(schema, types=dict(array=(list, tuple)))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: create.<locals>.Validator.__init__() got an unexpected keyword argument 'types' I honestly don't see why tuples couldn't be accepted by default. It's true that |
Previous method is deprecated from the
It requires much more code than earlier, but it's possible to make tuples valid. Btw, I agree that it should be supported by default. |
I'm in agreement with @pekkaklarck, @stojan-jovic and others, tuple should be a valid default. Building off @stojan-jovic's workaround, I've updated a portion of their code to grab the latest validator. import jsonschema
LatestValidator = jsonschema.validators._LATEST_VERSION
def list_and_tuple(checker, instance):
return isinstance(instance, (list, tuple))
type_checker = LatestValidator.TYPE_CHECKER.redefine(
'array', list_and_tuple,
)
CustomValidator = jsonschema.validators.extend(
LatestValidator,
type_checker=type_checker,
) Thanks @stojan-jovic! |
Currently, it's impossible to use tuples as arrays, only lists.
Array type should be a tuple like (list, tuple).
or
, where
The text was updated successfully, but these errors were encountered: