Skip to content

jp.parent(o, failingPath) throws meaningless error #173

Open

Description

@Phrogz
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions