Skip to content

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

@chr-hertel

Description

@chr-hertel

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