jmespath.py icon indicating copy to clipboard operation
jmespath.py copied to clipboard

Add support for 'arraylike' objects as JSON arrays

Open calgray opened this issue 2 years ago • 0 comments

JMESPath.py is limited in that only the dict and list derived containers returned by the built-in json library are supported in the object hierarchy due to the use of isinstance. A very notable arraylike instance that does not derive directly from these containers is a numpy.ndarray which can be deserialized using the JSON-like msgpack library with msgpack_numpy.

This changeset aims to add support for arraylike (list, tuple and numpy.ndarray) containers in place of parsed JSON arrays and without adding any dependency on the numpy library. This is done using the documented numpy array interface protocol of which many more arraylike libraries adhere to such as xarray, dask, astropy and cupy.

(pandas.Series is also arraylike but limited to 1D as multidimensional Series isn't an intended use case and has slicing issues)

calgray avatar Sep 18 '23 04:09 calgray