RFC 6902 JSON Patch: smart diffs, patching, audit and versioning.

Alto JSON Patch applies RFC 6902 operations and generates deterministic patches between PHP values.

<?php
use Alto\JsonPatch\JsonPatch;

$document = ['status' => 'draft'];
$patch = [
    ['op' => 'replace', 'path' => '/status', 'value' => 'published'],
];

$result = JsonPatch::apply($document, $patch);

Introduction

Patching

  • Applying: use the six RFC 6902 operations and handle failures.
  • Diffing: generate stable object and list changes.
  • Pointers: address document values with RFC 6901 paths.

The package transforms in-memory values and JSON strings. Persistence, authorization, version storage, and conflict resolution remain application responsibilities.

Patch operations

Start from one document, then inspect the PHP and its resulting JSON.

PHPInput
$document = [
    'status' => 'draft',
    'version' => 1,
    'owner' => 'alto',
];
JSONOriginal
  1. {
  2. "status": "draft",
  3. "version": 1,
  4. "owner": "alto"
  5. }
Original, 1 of 5