PHPackages                             bor3y/json-patch-php - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. bor3y/json-patch-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bor3y/json-patch-php
====================

Produce and apply json-patch objects

0.1.0(11y ago)0277LGPL-3.0PHP

Since Jun 12Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Bor3y/json-patch-php)[ Packagist](https://packagist.org/packages/bor3y/json-patch-php)[ RSS](/packages/bor3y-json-patch-php/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (3)Used By (0)

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

[](#json-patch-php)

Produce and apply json-patch objects.

Implements IETF JSON-patch (RFC 6902) and JSON-pointer (RFC 6901):

Using with Composer
-------------------

[](#using-with-composer)

To use this library as a Composer dependency in your project, include the following sections in your project's `composer.json` file:

```
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/mikemccabe/json-patch-php"
        }
    ],
    "require": {
        "mikemccabe/json-patch-php": "dev-master"
    }

```

Then, in your project's code, use the `JsonPatch` class definition from the `mikemccabe\JsonPatch` namespace like so:

```
use mikemccabe\JsonPatch\JsonPatch;
```

Entry points
------------

[](#entry-points)

- JsonPatch::get($doc, $pointer) - get a value from a json document
- JsonPatch::patch($doc, $patches) - apply patches to $doc and return result
- JsonPatch::diff($src, $dst) - return patches to create $dst from $src

Arguments are PHP arrays, i.e. the output of json\_decode($json\_string, 1)

(Note that you MUST pass 1 as the second argument to json\_decode to get an array. This library does not work with stdClass objects.)

All structures are implemented directly as PHP arrays. An array is considered to be 'associative' (e.g. like a JSON 'object') if it contains at least one non-numeric key.

Because of this, empty arrays (\[\]) and empty objects ({}) compare the same, and (for instance) an 'add' of a string key to an empty array will succeed in this implementation where it might fail in others.

$simplexml\_mode is provided to help with working with arrays produced from XML in the style of simplexml - e.g. repeated XML elements are expressed as arrays. When $simplexml\_mode is enabled, leaves with scalar values are implicitly treated as length-1 arrays, so this test will succeed:

```
{ "comment": "basic simplexml array promotion",
  "doc": { "foo":1 },
  "patch": [ { "op":"add", "path":"/foo/1", "value":2 } ],
  "expected": { "foo":[1, 2] } },

```

Also, when $simplexml\_mode is true, 1-length arrays are converted to scalars on return from patch().

Tests
-----

[](#tests)

Some tests are in a submodule (). Do 'git submodule init' to pull these, then 'php runtests.php' to run them.

[![Build Status](https://camo.githubusercontent.com/46d08751f1d3d9b243f7fcb56a379b39b6b705698b136f2cdf3efee2476c180a/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6d696b656d63636162652f6a736f6e2d70617463682d7068702e706e67)](http://travis-ci.org/mikemccabe/json-patch-php)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

4150d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/89e9ee489464baae55b853f9bbd3e79fe7e47aae7cfcd65297c18713dbe24eb9?d=identicon)[Bor3y](/maintainers/Bor3y)

---

Top Contributors

[![ycombinator](https://avatars.githubusercontent.com/u/51061?v=4)](https://github.com/ycombinator "ycombinator (8 commits)")[![bendiy](https://avatars.githubusercontent.com/u/571574?v=4)](https://github.com/bendiy "bendiy (5 commits)")[![warpech](https://avatars.githubusercontent.com/u/566463?v=4)](https://github.com/warpech "warpech (4 commits)")[![mikemccabe](https://avatars.githubusercontent.com/u/116425?v=4)](https://github.com/mikemccabe "mikemccabe (4 commits)")[![Bor3y](https://avatars.githubusercontent.com/u/8600326?v=4)](https://github.com/Bor3y "Bor3y (3 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (1 commits)")[![rfussien](https://avatars.githubusercontent.com/u/3856033?v=4)](https://github.com/rfussien "rfussien (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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