dchester / jsonpath

Query and manipulate JavaScript objects with JSONPath expressions. Robust JSONPath engine for Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`jp.parent(o, failingPath)` throws meaningless error

Phrogz opened this issue · comments

const jp = require('jsonpath')
let o = {a:1}
console.log(jp.parent(o, '$.a'))
// { a: 1 }

jp.parent(o, '$.DOESNOTEXIST')

// Uncaught TypeError: Cannot read properties of undefined (reading 'path')
//    at JSONPath.parent (./node_modules/jsonpath/lib/index.js:26:18)
  1. I expected this to work, since the parent does exist. (I expected the parser of the expression to drop the final term and resolve the path, instead of resolving the path and then backing up one.)
  2. If I did jp.parent({}, '$.foo.bar.jim.jam') I would expect it to return null, or an empty array, not to error out on some internal code.