adriank / ObjectPath

The agile query language for semi-structured data

Home Page:http://objectpath.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wierd result for queries on non-object elements

opened this issue · comments

Invalid queries return valid results on non-object elements of the tree (e.g. numbers, strings, sequence of strings)

Using the dataset from main page:

$ objectpath -u "http://api.openweathermap.org/data/2.5/box/city?bbox=12,32,15,37,10&cluster=yes"
>>> $.cnt
15
>>> $.cnt.11
15
>>> $.cnt.wtf?
15
>>> $.cod.foo
"200"
>>> $.cod.foo.asd
"200"
>>> $.cod.foo.asd[asd]
"200"
>>> $.cod.foo.bar['???']
"200"

Same applies to sequences of strings:

$ cat > test.json
{"list": [1,2,3,4]}
$ objectpath test.json
>>> $.list
[
  1,
  2,
  3,
  4
]
>>> $.list.123
[
  1,
  2,
  3,
  4
]
>>> $.list.abc
[]

in Python last line yields an empty generator.

Sorry for the late response. I'm travelling much recently.

All of this are intended behaviors, despite it seems odd. OP is designed to be friendly to beginners and powerful for super-users. First group greatly appreciate that invalid queries return what they need, second group (like you) know that the query is invalid anyway. :)

Nevertheless, I need to think whether supporting edge cases vs overall language consistency is more important.

BTW. I'm focusing on JS version of ObjectPath. Python has it's limitations and developing ObjectPath became overly complicated. JS is more low level language and has native support for JSON so its simpler. Check it out if you like at https://github.com/adriank/ObjectPath.JS