JSON Patch

JSON Patch Documentation

Everything you need to know about RFC 6902 JSON Patch operations
RFC 6902
IETF Standard
Last updated: July 2025

What is JSON Patch?

JSON Patch (RFC 6902) is a format for describing changes to a JSON document. It defines a JSON document structure for expressing a sequence of operations to apply to a target JSON document.

Instead of sending entire objects when making updates, JSON Patch lets you send only the specific changes needed. This makes it incredibly efficient for APIs, real-time applications, and data synchronization.

JSON Patch Operations

1. Add Operation

Adds a value to an object or inserts it into an array.

{ "op": "add", "path": "/name", "value": "John Doe" }

2. Remove Operation

Removes a value from an object or array.

{ "op": "remove", "path": "/email" }

3. Replace Operation

Replaces a value. Equivalent to a remove followed by an add.

{ "op": "replace", "path": "/age", "value": 30 }

4. Move Operation

Moves a value from one location to another.

{ "op": "move", "from": "/old-path", "path": "/new-path" }

5. Copy Operation

Copies a value from one location to another.

{ "op": "copy", "from": "/source", "path": "/destination" }

6. Test Operation

Tests that a value at the target location is equal to a specified value.

{ "op": "test", "path": "/version", "value": "1.0" }

Real-World Use Cases

REST API Updates

Send PATCH requests with only the changes instead of the entire resource. Reduces bandwidth and improves performance, especially for large objects.

Real-time Collaboration

Sync changes between multiple users editing the same document. Used by collaborative editors like Google Docs, Notion, and Figma.

Version Control

Track incremental changes to configuration files, database records, or any JSON data structure.

Database Operations

Update only modified fields in NoSQL databases like MongoDB, CouchDB, or DynamoDB.

Best Practices

Always validate patches before applying them to prevent security issues

Use atomic operations when possible to ensure data consistency

Test operations to verify conditions before making changes

Order matters - operations are applied sequentially

Use meaningful paths that are easy to understand and maintain

Quick Links

Popular Libraries

JavaScript: fast-json-patch

Python: jsonpatch

Java: jackson-json-patch

Go: json-patch

PHP: json-patch-php