PHPackages                             lindelius/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. lindelius/php-json-patch

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

lindelius/php-json-patch
========================

A zero-dependency PHP implementation of JSON Patch

0.1.1(4y ago)26.9k↓50%[1 PRs](https://github.com/lindelius/php-json-patch/pulls)Apache-2.0PHPPHP ^7.4||^8.0

Since May 25Pushed 4y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

php-json-patch
==============

[](#php-json-patch)

[![CircleCI](https://camo.githubusercontent.com/97fa16af923aecb49b59d64567b8f1709c0438b43dd9fb48f457572c7a4bc91a/68747470733a2f2f636972636c6563692e636f6d2f67682f6c696e64656c6975732f7068702d6a736f6e2d70617463682e7376673f7374796c653d736869656c64)](https://circleci.com/gh/lindelius/php-json-patch)[![Coverage Status](https://camo.githubusercontent.com/dd48c8a80ba1677cffac71b1b8d72c06008a850ed321d4e1122d0eacfdf4a1d1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6c696e64656c6975732f7068702d6a736f6e2d70617463682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/lindelius/php-json-patch?branch=master)

A zero-dependency PHP implementation of JSON Patch ([RFC 6902](https://tools.ietf.org/html/rfc6902)).

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Protected Paths](#protected-paths)

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

[](#requirements)

- PHP 7.4, or higher

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

[](#installation)

If you are using Composer, you may install the latest version of this library by running the following command from your project's root folder:

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

```

You may also manually download the library by navigating to the "Releases" page and then expanding the "Assets" section of the latest release.

Usage
-----

[](#usage)

Given a set of JSON Patch operations...

```
[
    { "op": "test", "path": "/name", "value": "Anakin Skywalker" },
    { "op": "replace", "path": "/name", "value": "Darth Vader" },
    { "op": "add", "path": "/order", "value": "Sith" },
    { "op": "move", "from": "/friends", "path": "/foes" }
]
```

And a document...

```
{
    "name": "Anakin Skywalker",
    "friends": ["Obi-Wan Kenobi", "Ahsoka Tano"],
    "order": "Jedi"
}
```

You can (atomically) apply the patches through one of the [`PatcherInterface`](src/PatcherInterface.php) methods...

```
// Option 1: Provide the raw JSON string
$newDocument = $patcher->patchFromJson($documentAsArray, $operationsAsJson);

// Option 2: Provide the JSON Patch operations in array format
$newDocument = $patcher->patch($documentAsArray, $operationsAsArray);
```

And get a new document back :)

```
{
    "name": "Darth Vader",
    "foes": ["Obi-Wan Kenobi", "Ahsoka Tano"],
    "order": "Sith"
}
```

### Protected Paths

[](#protected-paths)

This library has built-in support for registering "protected paths", which are paths that may not be modified by any patch operation. Protected paths will indirectly also block modifications to their parent path(s) and any child paths.

```
$patcher->addProtectedPath("/id");
$patcher->addProtectedPath("/created_at");
$patcher->addProtectedPath("/some/nested/path");
```

Please note that "test" operations can still operate on a protected path since they are not actually modifying the document.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Total

2

Last Release

1769d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8205651?v=4)[Tom Lindelius](/maintainers/lindelius)[@lindelius](https://github.com/lindelius)

---

Top Contributors

[![lindelius](https://avatars.githubusercontent.com/u/8205651?v=4)](https://github.com/lindelius "lindelius (23 commits)")

---

Tags

jsonjson-patchjsonjson patch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lindelius-php-json-patch/health.svg)

```
[![Health](https://phpackages.com/badges/lindelius-php-json-patch/health.svg)](https://phpackages.com/packages/lindelius-php-json-patch)
```

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30422.2M45](/packages/colinodell-json5)[clue/ndjson-react

Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.

15467.7M16](/packages/clue-ndjson-react)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
