PHPackages                             makasim/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. makasim/json-patch-php

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

makasim/json-patch-php
======================

Produce and apply json-patch objects

0.1.2(6y ago)08341LGPL-3.0PHP

Since Jun 12Pushed 6y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (5)Used By (1)

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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity56

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

Every ~1610 days

Total

2

Last Release

2537d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4ac9e6a18ae68dd3f81d0cb5a723459970b208fc60187ea8329d69a8d437f22?d=identicon)[makasim](/maintainers/makasim)

---

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)")[![makasim](https://avatars.githubusercontent.com/u/143206?v=4)](https://github.com/makasim "makasim (2 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/makasim-json-patch-php/health.svg)

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

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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