@@ -31,6 +31,13 @@ public function testChildOperators(): void
3131 self ::assertEquals ('Sayings of the Century ' , $ result [0 ]);
3232 }
3333
34+ public function testIndexesObject (): void
35+ {
36+ $ result = (new JSONPath ($ this ->exampleIndexedObject (random_int (0 , 1 ))))->find ('$.store.books[3].title ' );
37+
38+ self ::assertEquals ('Sword of Honour ' , $ result [0 ]);
39+ }
40+
3441 /**
3542 * $['store']['books'][0]['title']
3643 *
@@ -800,22 +807,61 @@ public function exampleDataWithSlashes(int $asArray = 1)
800807 public function exampleDataWithDots (int $ asArray = 1 )
801808 {
802809 $ json = '
803- {
804- "data": {
805- "tokens": [
806- {
807- "Employee.FirstName": "Jack"
808- },
809- {
810- "Employee.LastName": "Daniels"
811- },
812- {
813- "Employee.Email": "[email protected] " 814- }
815- ]
816- }
817- }
818- ' ;
810+ {
811+ "data": {
812+ "tokens": [
813+ {
814+ "Employee.FirstName": "Jack"
815+ },
816+ {
817+ "Employee.LastName": "Daniels"
818+ },
819+ {
820+ "Employee.Email": "[email protected] " 821+ }
822+ ]
823+ }
824+ }
825+ ' ;
826+
827+ return json_decode ($ json , $ asArray === 1 );
828+ }
829+
830+ public function exampleIndexedObject (int $ asArray = 1 )
831+ {
832+ $ json = '
833+ {
834+ "store":{
835+ "books":{
836+ "4": {
837+ "category":"reference",
838+ "author":"Nigel Rees",
839+ "title":"Sayings of the Century",
840+ "price":8.95
841+ },
842+ "3": {
843+ "category":"fiction",
844+ "author":"Evelyn Waugh",
845+ "title":"Sword of Honour",
846+ "price":12.99
847+ },
848+ "2": {
849+ "category":"fiction",
850+ "author":"Herman Melville",
851+ "title":"Moby Dick",
852+ "isbn":"0-553-21311-3",
853+ "price":8.99
854+ },
855+ "1": {
856+ "category":"fiction",
857+ "author":"J. R. R. Tolkien",
858+ "title":"The Lord of the Rings",
859+ "isbn":"0-395-19395-8",
860+ "price":22.99
861+ }
862+ }
863+ }
864+ } ' ;
819865
820866 return json_decode ($ json , $ asArray === 1 );
821867 }
0 commit comments