Skip to content

Negating the filter expression using ! is not working #151

Description

@Parth-Rewind

Sample JSON: Response from Github when getting a list of all issues
The response contains two objects, one with a pull_request property and the other doesn't have a pull_request property.

[
  {
    "id": 1,
    "pull_request": {
      "url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347",
      "html_url": "https://github.com/octocat/Hello-World/pull/1347",
      "diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff",
      "patch_url": "https://github.com/octocat/Hello-World/pull/1347.patch"
    },
    "updated_at": "2011-04-22T13:33:48Z"
  },
  {
    "id": 2,
    "updated_at": "2011-04-22T13:33:48Z"
  }
]

Bug

The request is to support this scenario

🔴 Failing scenario. Cannot negate a filter expression using !

Intent:
Get all objects from sample json data that don't have a pull_request property

Query

JsonPath.new('$[?(!@.pull_request)]').on(json)

🐞 Actual Result:

[]

Expected Result

[
  {
    "id": 2,
    "updated_at": "2011-04-22T13:33:48Z"
  }
]

Result From Jsonpath.com
Screenshot 2023-02-22 at 8 16 21 AM


🟢 Passing scenario. This scenario is working fine and as intended.

Intent:
Get all objects from sample data with the pull_request property in the response

Query

JsonPath.new('$[?(@.pull_request)]').on(json)

Result from JsonPath

[
  {
    'id' => 1,
    'pull_request' => {
      'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1347',
      'html_url' => 'https://github.com/octocat/Hello-World/pull/1347',
      'diff_url' => 'https://github.com/octocat/Hello-World/pull/1347.diff',
      'patch_url' => 'https://github.com/octocat/Hello-World/pull/1347.patch'
    },
    'updated_at' => '2011-04-22T13:33:48Z'
  }
]

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