JSONPath-Plus / JSONPath

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

Cannot read properties of undefined (reading 'match') on an absent field #218

Open Scratch-net opened 4 hours ago

Scratch-net commented 4 hours ago

Describe the bug

This error gets thrown if match field does not exist

Code sample or steps to reproduce

{
    "items":[
        {
            "name": "John Doe",
            "country": "USA"
        },
        {
          "country": "USA",
          "age":25
        }
    ]
}

//fails $.items[?(@.name.match(/.*oe/))]

//only way to make it work $.items[?(@.name && @.name.match(/.*oe/))]

Console error or logs

Error: jsonPath: Cannot read properties of undefined (reading 'match'): @.name.match(/.*abc/)

at JSONPath.Object.<anonymous>.JSONPath._eval
at JSONPath.Object.<anonymous>.JSONPath._walk
at JSONPath.Object.<anonymous>.JSONPath._trace
at JSONPath.Object.<anonymous>.JSONPath._trace
at JSONPath.Object.<anonymous>.JSONPath.evaluate

Expected behavior

no error gets thrown, no results returned

Environment (IMPORTANT)

Desktop**

brettz9 commented 3 hours ago

In the json-path-comparison project, this does look like it should work per this example (which does indeed err in jsonpath-plus): https://cburgmer.github.io/json-path-comparison/results/filter_expression_with_subpaths_deeply_nested.html

PRs welcome.