jmespath / jmespath.py

JMESPath is a query language for JSON.
http://jmespath.org
MIT License
2.19k stars 181 forks source link

Allow for subclassed types #158

Open mkrizek opened 6 years ago

mkrizek commented 6 years ago

A little background first, in Ansible there is a json_query filter plugin which uses jmespath to query json. There is an issue open where users of that plugin get the following error:

JMESPathTypeError: In function contains(), invalid type for value: irb.1111, expected one of: ['array', 'string'], received: "unknown"

The comment that summarizes the issue is here https://github.com/ansible/ansible/issues/27299#issuecomment-366781707.

The error is caused by the fact that Ansible uses its own types for strings. One of the hacks we've come up with was:

jmespath.functions.REVERSE_TYPES_MAP['string'] = jmespath.functions.REVERSE_TYPES_MAP['string'] + ('AnsibleUnicode', 'AnsibleUnsafeText',)

which seems weird since I am pretty sure REVERSE_TYPES_MAP is not supposed to be public.

is there a proper way to do this? If not, is this something that would be considered to be added?

Thanks!

mkrizek commented 6 years ago

cc @jamesls

jamesls commented 6 years ago

There's not a good way to do this now throuhg a public interface but I'm not opposed to adding something to make this easier. Having less restrictive type checking has come up a few times.

jeking3 commented 6 years ago

@jamesls would you be able to add this public interface that allows the consumer of jmespath to teach jmespath about additional types that are convertible to string? Or do you need someone in the community to do it?

jeking3 commented 5 years ago

@jamesls are you still there?

jamesls commented 4 years ago

So I'm not opposed to this feature, but offhand I don't have any thoughts on a better public API for this. If anyone has suggestions, I'm open to it. I suppose we'd add something to the Options class?

Once we have an interface we like, I can take a crack at implementing this.