sean2077/jsonpath-python

Not possible to compare str and int when sorting

Opened this issue · 0 comments

Great library. Thanks.

Problem:

Today I noticed that it crashed when you have a list of objects which is then sorted and the keys have different data types.

TypeError: '<' not supported between instances of 'str' and 'int'

in init.py in _sorter at line 205
with

obj=[[
0, {
code: 0, 
someothervalue: 'asd'
}],
[
1, {
code: 'N', 
someothervalue: 'dfdf'
}]]

and
sortby=code

Expected behaviour:

Since there is no rfc for JSON path, I am not sure what the conventional behaviour is then. I assume that sorting by casting all to string makes sense if one of them is a string. Other option would be to throw a custom error.