PHPackages                             remorhaz/php-json-patch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. remorhaz/php-json-patch

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

remorhaz/php-json-patch
=======================

JSON Patch (RFC-6902) PHP implementation

v0.6.1(2y ago)678.0k↓33.8%1MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0

Since Nov 9Pushed 2y ago2 watchersCompare

[ Source](https://github.com/remorhaz/php-json-patch)[ Packagist](https://packagist.org/packages/remorhaz/php-json-patch)[ Docs](https://github.com/remorhaz/php-json-patch)[ RSS](/packages/remorhaz-php-json-patch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (15)Used By (0)

PHP JSON Patch
==============

[](#php-json-patch)

[![Latest Stable Version](https://camo.githubusercontent.com/dbe6c35f4b0364b935606ae0242110b45c4f544261669c2e2b542bde91f17850/68747470733a2f2f706f7365722e707567782e6f72672f72656d6f7268617a2f7068702d6a736f6e2d70617463682f762f737461626c65)](https://packagist.org/packages/remorhaz/php-json-patch)[![Build](https://github.com/remorhaz/php-json-patch/actions/workflows/build.yml/badge.svg)](https://github.com/remorhaz/php-json-patch/actions/workflows/build.yml)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8359ab4c72b301870a7bf29e9c07e7cfc09ba005c6fa98968f66673fc90de1f8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72656d6f7268617a2f7068702d6a736f6e2d70617463682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/remorhaz/php-json-patch/?branch=master)[![codecov](https://camo.githubusercontent.com/08dc7a5819075c6a06cfa966ddb369476e59ee14f07fd6dcd23703868316aaac/68747470733a2f2f636f6465636f762e696f2f67682f72656d6f7268617a2f7068702d6a736f6e2d70617463682f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/remorhaz/php-json-patch)[![Mutation testing badge](https://camo.githubusercontent.com/d3a3ddbac2316657f162cfbf3487785fc186d59f59da00eee33e8ede95d37ea5/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d25324672656d6f7268617a2532467068702d6a736f6e2d70617463682532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/remorhaz/php-json-patch/master)[![Total Downloads](https://camo.githubusercontent.com/d8a0f46211c972e663b89af91a19f02d164f96b3a3e7924ceb42eb0a533429f5/68747470733a2f2f706f7365722e707567782e6f72672f72656d6f7268617a2f7068702d6a736f6e2d70617463682f646f776e6c6f616473)](https://packagist.org/packages/remorhaz/php-json-patch)[![License](https://camo.githubusercontent.com/257d46e58578985bc2348749d9c615c11da6d9a8fddc24874980430d6ad1af49/68747470733a2f2f706f7365722e707567782e6f72672f72656d6f7268617a2f7068702d6a736f6e2d70617463682f6c6963656e7365)](https://packagist.org/packages/remorhaz/php-json-patch)

This library implements [RFC6902](https://tools.ietf.org/html/rfc6902)-compliant JSON patch tool.

Requirements
------------

[](#requirements)

- PHP 8.1.
- [JSON extension](https://www.php.net/manual/en/book.json.php) (ext-json) - required by [remorhaz/php-json-data](https://github.com/remorhaz/php-json-data) to access JSON documents.
- [Internationalization functions](https://www.php.net/manual/en/book.intl.php) (ext-intl) - required by [`remorhaz/php-json-data`](https://github.com/remorhaz/php-json-data) to compare Unicode strings.

Installation
------------

[](#installation)

You will need [composer](https://getcomposer.org) to perform install.

```
composer require remorhaz/php-json-patch

```

Documentation
-------------

[](#documentation)

### Accessing JSON document

[](#accessing-json-document)

You can create accessible JSON document either from encoded JSON string or from decoded JSON data using corresponding *node value factory*:

```
use Remorhaz\JSON\Data\Value\EncodedJson;
use Remorhaz\JSON\Data\Value\DecodedJson;

// Creating document from JSON-encoded string:
$encodedValueFactory = EncodedJson\NodeValueFactory::create();
$encodedJson = '{"a":1}';
$document1 = $encodedValueFactory->createValue($encodedJson);

// Creating document from decoded JSON data:
$decodedValueFactory = DecodedJson\NodeValueFactory::create();
$decodedJson = (object) ['a' => 1];
$document2 = $decodedValueFactory->createValue($decodedJson);
```

### Creating and processing query

[](#creating-and-processing-query)

You should use *query factory* to create query from JSON Patch document. Then you should use *processor* to apply that query:

```
