Download the PHP package alto/json-patch without Composer

On this page you can find all versions of the php package alto/json-patch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-patch

ALTO \ JSON Patch

A strict, auditable JSON Patch implementation for PHP 8.3+. This library handles two concerns with precision:

  1. Apply: A deterministic RFC 6902 engine that replays patches exactly.
  2. Diff: A smart diff generator that produces stable, readable patches.

Built for systems where change history matters.


  PHP Version   CI   Packagist Version   PHP Version   PHP Version  

Installation

Why Alto JSON Patch?

For audit logs: Deterministic apply means you can verify patch integrity. Store the parent hash, the patch, and the result hash. Replaying the patch will always produce the same result.

For readable diffs: Generate clean patches that humans can review. Optional identity-based list diffing produces granular operations instead of replacing entire arrays.

For reliability: Pure PHP with strict types. No magic, no surprises.

Quick Start

Generate Patches

Create patches automatically by diffing two states:

Smart List Diffing

By default, lists are replaced entirely when they differ. For granular control, use identity-based diffing:

This produces readable patches where reviewers can see exactly which items changed.

Utility Methods

Audit Trail Example

Supported Operations

All RFC 6902 operations:

Error Handling

Operations throw JsonPatchException with clear messages:

Advanced Usage

Float Comparison

JsonPatch uses strict equality (===) for values. Be aware that json_decode may treat numbers differently depending on flags. For example, 1.0 (float) is not strictly equal to 1 (int). Ensure your input documents use consistent types if strict equality is required.

Limitations

applyJson: Empty Object vs Array

When using JsonPatch::applyJson(), the underlying json_decode converts empty JSON objects {} into empty PHP arrays []. Since PHP does not distinguish between empty associative arrays (objects) and empty indexed arrays (lists), an input of {"key": {}} may result in {"key": []} after a round-trip. If strictly preserving {} vs [] is critical, consider using apply() with pre-decoded structures where you can control the object mapping (e.g. json_decode($json, false) for stdClass).

API Reference

JsonPatch

Method Description
apply(array $doc, array $patch): array Apply a patch to a document
applyJson(string $docJson, string $patchJson, int $flags = 0): string Apply patch to JSON string
diff(array $from, array $to, ?DiffOptions $opts = null): array Generate patch from two states
get(array $doc, string $path): mixed Get value at JSON pointer path
test(array $doc, string $path, mixed $value): bool Test if value matches at path
validate(array $patch): array Validate patch structure, returns errors

DiffOptions

Configure identity-based list diffing:

License

This project is licensed under the MIT License - see the LICENSE file for details.


All versions of json-patch with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package alto/json-patch contains the following files

Loading the files please wait ...