@@ -49,6 +49,19 @@ public function testAllAuthors()
4949 ], $ result );
5050 }
5151
52+ public function testAllAuthorsWithBrackets ()
53+ {
54+ $ result = self ::getBookstoreCrawler ()->find ('$..["author"] ' );
55+
56+ $ this ->assertCount (4 , $ result );
57+ $ this ->assertSame ([
58+ 'Nigel Rees ' ,
59+ 'Evelyn Waugh ' ,
60+ 'Herman Melville ' ,
61+ 'J. R. R. Tolkien ' ,
62+ ], $ result );
63+ }
64+
5265 public function testAllThingsInStore ()
5366 {
5467 $ result = self ::getBookstoreCrawler ()->find ('$.store.* ' );
@@ -58,6 +71,15 @@ public function testAllThingsInStore()
5871 $ this ->assertArrayHasKey ('color ' , $ result [1 ]);
5972 }
6073
74+ public function testAllThingsInStoreWithBrackets ()
75+ {
76+ $ result = self ::getBookstoreCrawler ()->find ('$["store"][*] ' );
77+
78+ $ this ->assertCount (2 , $ result );
79+ $ this ->assertCount (4 , $ result [0 ]);
80+ $ this ->assertArrayHasKey ('color ' , $ result [1 ]);
81+ }
82+
6183 public function testEscapedDoubleQuotesInFieldName ()
6284 {
6385 $ crawler = new JsonCrawler (<<<JSON
@@ -77,6 +99,14 @@ public function testBasicNameSelector()
7799 $ this ->assertSame ('Nigel Rees ' , $ result [0 ]['author ' ]);
78100 }
79101
102+ public function testBasicNameSelectorWithBrackts ()
103+ {
104+ $ result = self ::getBookstoreCrawler ()->find ('$["store"]["book"] ' )[0 ];
105+
106+ $ this ->assertCount (4 , $ result );
107+ $ this ->assertSame ('Nigel Rees ' , $ result [0 ]['author ' ]);
108+ }
109+
80110 public function testAllPrices ()
81111 {
82112 $ result = self ::getBookstoreCrawler ()->find ('$.store..price ' );
@@ -121,6 +151,17 @@ public function testBooksWithIsbn()
121151 ], [$ result [0 ]['isbn ' ], $ result [1 ]['isbn ' ]]);
122152 }
123153
154+ public function testBooksWithBracketsAndFilter ()
155+ {
156+ $ result = self ::getBookstoreCrawler ()->find ('$..["book"][?(@.isbn)] ' );
157+
158+ $ this ->assertCount (2 , $ result );
159+ $ this ->assertSame ([
160+ '0-553-21311-3 ' ,
161+ '0-395-19395-8 ' ,
162+ ], [$ result [0 ]['isbn ' ], $ result [1 ]['isbn ' ]]);
163+ }
164+
124165 public function testBooksLessThanTenDollars ()
125166 {
126167 $ result = self ::getBookstoreCrawler ()->find ('$..book[?(@.price < 10)] ' );
@@ -216,6 +257,14 @@ public function testEverySecondElementReverseSlice()
216257 $ this ->assertSame ([6 , 2 , 5 ], $ result );
217258 }
218259
260+ public function testEverySecondElementReverseSliceAndBrackets ()
261+ {
262+ $ crawler = self ::getSimpleCollectionCrawler ();
263+
264+ $ result = $ crawler ->find ('$["a"][::-2] ' );
265+ $ this ->assertSame ([6 , 2 , 5 ], $ result );
266+ }
267+
219268 public function testEmptyResults ()
220269 {
221270 $ crawler = self ::getSimpleCollectionCrawler ();
@@ -404,6 +453,19 @@ public function testAcceptsJsonPath()
404453 $ this ->assertSame ('red ' , $ result [0 ]['color ' ]);
405454 }
406455
456+ public function testStarAsKey ()
457+ {
458+ $ crawler = new JsonCrawler (<<<JSON
459+ {"*": {"a": 1, "b": 2}, "something else": {"c": 3}}
460+ JSON );
461+
462+ $ result = $ crawler ->find ('$["*"] ' );
463+
464+ $ this ->assertCount (1 , $ result );
465+ $ this ->assertSame (['a ' => 1 , 'b ' => 2 ], $ result [0 ]);
466+ }
467+
468+
407469 private static function getBookstoreCrawler (): JsonCrawler
408470 {
409471 return new JsonCrawler (<<<JSON
0 commit comments