Skip to content

Commit

Permalink
Merge pull request #170 from supermetrics-public/chore/ReadmeUsageExc…
Browse files Browse the repository at this point in the history
…eption

Add exception catching to usage section in README
  • Loading branch information
crocodele authored Sep 11, 2023
2 parents 222f9ec + cd8c528 commit 5fabf64
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 5fabf64

Please sign in to comment.