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

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

get-zen/json-patch-php
======================

Produce and apply json-patch objects. Forked from mikemccabe/json-patch-php (https://github.com/mikemccabe/json-patch-php). THIS FORK adds an `ensure` operation that sets a value at a given path, creating any missing intermediate structure (deep upsert semantics). Just set the damned field!

0.2.0(1y ago)099↓100%LGPL-3.0PHPPHP &gt;=5.3

Since Jan 5Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (4)Used By (0)

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

[](#json-patch-php)

Forked from [mikemccabe/json-patch-php](https://github.com/mikemccabe/json-patch-php).

Produce and apply json-patch objects.

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

Extensions
----------

[](#extensions)

Adds custom `ensure` operation (`op`) that replaces the value at target path or creates it if the path does not exist. (alpha!!! works in production, no angry customers so far)

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

[](#using-with-composer)

```
composer require get-zen/json-patch-php

```

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

```
use GetZen\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 (!!!! Not maintained)
---------------------------

[](#tests--not-maintained)

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

38

—

LowBetter than 85% of packages

Maintenance70

Regular maintenance activity

Popularity10

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor3

3 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 ~1863 days

Total

3

Last Release

424d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9bb6213442025e5e9a928557b8b61f73f277636f953c73c65eb42b5fc326f8d5?d=identicon)[mholecek](/maintainers/mholecek)

![](https://avatars.githubusercontent.com/u/1252386?v=4)[josefsabl](/maintainers/josefsabl)[@josefsabl](https://github.com/josefsabl)

---

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)")[![mikemccabe](https://avatars.githubusercontent.com/u/116425?v=4)](https://github.com/mikemccabe "mikemccabe (4 commits)")[![warpech](https://avatars.githubusercontent.com/u/566463?v=4)](https://github.com/warpech "warpech (4 commits)")[![josefsabl](https://avatars.githubusercontent.com/u/1252386?v=4)](https://github.com/josefsabl "josefsabl (4 commits)")[![josefsablmafra](https://avatars.githubusercontent.com/u/141149743?v=4)](https://github.com/josefsablmafra "josefsablmafra (1 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/get-zen-json-patch-php/health.svg)

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

###  Alternatives

[elfsundae/laravel-hashid

A simple, elegant way to obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.

415246.3k2](/packages/elfsundae-laravel-hashid)[tapp/laravel-aws-secrets-manager

Use AWS Secrets manager to load environment variables for configuration.

37208.6k](/packages/tapp-laravel-aws-secrets-manager)

PHPackages © 2026

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