public function getItemsOf($collection) { if (file_exists($this->dataFilePath)) { $dataJSON = $this->fileGetJSON(); $jsonObject = new JsonObject($dataJSON); $jsonResult = $jsonObject->get('$.' . $collection . '[*]'); if ($jsonResult) { return $jsonResult; } return []; } else { $this->initDataFile(); } }
/** * testParsingErrors * * @param string $jsonPath jsonPath * * @return void * @dataProvider testParsingErrorsProvider */ public function testParsingErrors($jsonPath, $token) { $jsonObject = new JsonObject($this->json); $exception = null; try { $jsonObject->get($jsonPath); } catch (InvalidJsonPathException $e) { $exception = $e; } $this->assertEquals($exception->getMessage(), "Error in JSONPath near '" . $token . "'"); }
} '; switch (count($argv)) { case 1: print "Usage: {$argv['0']} <jsonpath> [<file to json>]\n"; print "If no json file is given it defaults to the json specified in http://goessner.net/articles/JsonPath/index.html#e3\n"; die; break; case 3: $json = file_get_contents($argv[2]); default: $jsonPath = $argv[1]; } try { $jsonObject = new JsonObject($json); } catch (InvalidJsonException $e) { print "Invalid JSON error: '" . $e->getMessage() . "'\r\n"; die; } try { $r = $jsonObject->get($jsonPath); } catch (InvalidJsonPathException $e) { print "Invalid JSONPath error: '" . $e->getMessage() . "'\r\n"; die; } if ($r === false) { print "false"; } else { print json_encode($r); } print "\r\n";
public function match(&$actual) { $json = new JsonObject($actual, true); $actualValue = $json->get($this->jsonPathSelector); return $actualValue == $this->_expected; }