dchester/jsonpath

Filters don't work when object is an array.

Opened this issue · 1 comments

Hello,

I've noticed that filters don't work when object is an array:

const jp = require('jsonpath');
const doesntWork = JSON.parse(
    `[
        {"test": "test1"},
        {"test": "test2"}
    ]`);
const works = {
    data: doesntWork
};

console.log(jp.query(doesntWork, '$..*[?(@.test == "test1")]'));  // []
console.log(jp.query(works, '$..*[?(@.test == "test1")]'));  // [ { test: 'test1' } ]

Interesting that $..* returns [ { test: 'test1' }, { test: 'test2' }, 'test1', 'test2' ] (as I'd expect), but $..*[*] leaves only [ 'test1', 'test2' ]. I.e. you get this result because when you filter there are only text items in array, not objects:

console.log(JsonPath.query(doesntWork, '$..*[?(@ == "test1")]'));  // [ 'test1' ]