Skip to content

@parent does not actually point to parent when used in a filter on an object #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iwb-rubentytgat opened this issue Oct 5, 2020 · 0 comments

Comments

@iwb-rubentytgat
Copy link

iwb-rubentytgat commented Oct 5, 2020

Describe the bug

When running a filter on an object instead of an array, the @parent property does not seem to point at the actual parent object, but at the parent of the parent.

It's easy to imagine where this comes from, since when using this filter on an array of objects, you'd have to go 2 levels up in order to get to the parent object instead of the array. This is however not the case when filtering over the entries of an object.

Code sample or steps to reproduce

I ran the following JSONPath in the browser demo. As you can see I put a console.log statement in the filter to monitor the values of @, @path, @parentProperty and @parent while it is running

$.foo.bar[?(@property === 'foo' && (console.log(@ , @path, @parentProperty, @parent), true))]

with the following JSON:

{
  "id": 1,
  "foo": {
    "id": 2,
    "bar": {
      "id": 3,
      "foo": {
        "id": 4
      }
    }
  }
}

Console error or logs

The console will show the following log:

Object { id: 4 }      $['foo']['bar']['foo']      bar      Object { id: 2, bar: {…} }

i.e. the @parent is not pointing to the object with id 3 as expected, but to it's parent.

Note that the @path and @parentProperty variables are set correctly. Only the @parent property is wrong.

Expected behavior

I would expect the following to be logged instead:

Object { id: 4 }      $['foo']['bar']['foo']      bar      Object { id: 3, foo: {…} }

Environment (IMPORTANT)

  • JSONPath-Plus version: whichever version is currently (2020-10-05) running in the live demo.

Desktop**

  • OS: Linux (NixOS)
  • Browser and version: Firefox 77.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant