Skip to content

Commit

Permalink
Improved the basic usage code sample in README.md with exception hand…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
blancks committed Aug 26, 2024
1 parent 0994b5a commit 40fb6fa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,26 @@ composer require blancks/fast-jsonpatch-php
<?php require_once 'vendor/autoload.php';

use blancks\JsonPatch\FastJsonPatch;
use blancks\JsonPatch\FastJsonPatch\exceptions\FastJsonPatchException;

$json = '{"name": "John", "age": 30}';
$patch = '[
{"op": "replace", "path": "/name", "value": "Jane"},
{"op": "add", "path": "/email", "value": "[email protected]"}
]';

echo FastJsonPatch::apply($json, $patch);
// Output: {"name": "Jane", "age": 30, "email": "[email protected]"}
try {

echo FastJsonPatch::apply($json, $patch);
// Output: {"name": "Jane", "age": 30, "email": "[email protected]"}

} catch(FastJsonPatchException $e) {

// FastJsonPatchException comes with two additional methods to fetch context data:
// $e->getContextPointer() may return the context JSON pointer for given error
// $e->getContextDocument() may return the portion of the document relevant for the error

}
```

## Methods Overview
Expand Down

0 comments on commit 40fb6fa

Please sign in to comment.