Skip to content

Commit

Permalink
Add exception catching to usage section in README
Browse files Browse the repository at this point in the history
  • Loading branch information
crocodele committed Sep 10, 2023
1 parent 222f9ec commit cd8c528
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ $ sudo service php-fpm restart
```php
<?php

$jsonPath = new \JsonPath\JsonPath();
use JsonPath\JsonPath;
use JsonPath\JsonPathException;

// Query a data array using a JSONPath expression string.
// Returns an array of matching elements, or false if nothing was found.
$result = $jsonPath->find($data, $selector);
$jsonPath = new JsonPath();

try {
// Query a data array using a JSONPath expression string.
// Returns an array of matching elements, or false if nothing was found.
$result = $jsonPath->find($data, $selector);
} catch (JsonPathException $exception) {
echo $exception->getMessage(); // Usually a syntax error in the selector
}
```

## Examples
Expand Down

0 comments on commit cd8c528

Please sign in to comment.