Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[JsonPath] Returning [0 => null] on path with length filter #61258

Copy link
Copy link
@chr-hertel

Description

@chr-hertel
Issue body actions

Symfony version(s) affected

7.3

Description

While working on symfony/ai#136 I found a behavior I'm not quite certain if intended or not.

With a JSON like this:

{
  "choices": [
    {
      "message": {
        "content": null
      }
    }
  ]
}

(Extended file)

And a JsonPath like this: $.choices[?length(@.message.content) >= 0].message.content

I get an array with null [0 => null], but would just expect [] as result.

How to reproduce

To add in JsonCrawlerTest:

    public function testEmptyLengthFunction()
    {
        $crawler = new JsonCrawler('{"choices": [{"message": {"content": null}}]}');
        $result = $crawler->find('$.choices[?length(@.message.content) >= 0].message.content');

        $this->assertSame([], $result);
    }

See chr-hertel#1

Possible Solution

I'm open for fixing this, but would need some serious pointers.

Additional Context

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.