Skip to content

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

Open
@iwb-rubentytgat

Description

@iwb-rubentytgat

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions