JSONPath-Plus / JSONPath

A fork of JSONPath from http://goessner.net/articles/JsonPath/
Other
963 stars 169 forks source link

path $..*[?(@ === false)] does not work as expected #136

Closed vk342 closed 3 years ago

vk342 commented 3 years ago

given an object

{"a":{"b":false}}

I expect "$..*[?(@ === false)]" to return a result, in fact, this search returns empty array

As far as I can tell, the issue is on line 674:

JSONPath.prototype._eval = function (
    code, _v, _vname, path, parent, parentPropName
) {
    if (!this._obj || !_v) { return false; }

because _v === false the expression nether evaluated

michelnev commented 3 years ago

I see similar issues with numeric values of zero.

{ "a": { "b": 0 } }

I'd expect this to return a match: "$.a[?(@property === 'b' && @ < 1)]" However, it returns an empty array.

brettz9 commented 3 years ago

Fix released in 5.0.4. Note that this change may now impact other uses of @ where it is not a scalar such as:

$..*[?(@ && @.prop === 'abc')]

Previously, without the @ &&, it would just silently fail to match, but now (as per other similar cases) it will throw.

@michelnev : You need to use @property lower case, but otherwise, the fix should address your case as well.