Inferensys

Glossary

JSON Patch

JSON Patch is a standard format defined by RFC 6902 for describing a sequence of operations (add, remove, replace, copy, move, test) to apply to a JSON document, enabling precise, programmatic modification of structured legal data.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
RFC 6902

What is JSON Patch?

JSON Patch is a standard format for expressing a sequence of operations to apply to a JSON document, enabling precise, programmatic modification of structured data.

JSON Patch defines a media type (application/json-patch+json) and a document structure containing an ordered list of operations—add, remove, replace, move, copy, and test—that are applied atomically to a target JSON document. Each operation specifies a target location using JSON Pointer (RFC 6901), a string syntax for referencing a specific value within a nested object hierarchy, ensuring unambiguous modification of even deeply nested legal data structures.

In document comparison engines, a JSON Patch serves as the machine-readable output of an algorithmic differencing process, representing the precise edit script between two versions of a structured contract or clause. This patch can be stored for change provenance, transmitted to apply updates, or used to programmatically reconstruct a modified document from an original, making it a foundational element for automated redline analysis and version control in legal AI systems.

RFC 6902

Key Features of JSON Patch

A media type for expressing a sequence of operations to apply to a target JSON document, enabling precise, programmatic modification of structured data without transmitting the entire document.

01

Atomic Operation Model

JSON Patch defines a transaction as an ordered list of operations. Each operation is an object with exactly three members: op, path, and value (or from for move/copy). The operations are applied sequentially, and if any single operation fails, the entire patch fails, preventing the document from being left in an inconsistent intermediate state. This atomicity is critical for maintaining data integrity in legal document pipelines.

02

Six Canonical Operations

The standard defines exactly six operations that form a complete set for any JSON transformation:

  • add: Inserts a new value at a specified path, creating missing parent objects/array elements as needed.
  • remove: Deletes the value at the target path, leaving the parent structure intact.
  • replace: Overwrites the value at the target path with a new value, equivalent to a remove followed by an add.
  • move: Relocates a value from a from path to the target path, removing it from the source location.
  • copy: Duplicates a value from a from path to the target path, leaving the source intact.
  • test: Asserts that the value at the target path equals a specified value, acting as a precondition guard.
03

JSON Pointer Path Syntax

All path and from members use JSON Pointer syntax as defined by RFC 6901. A JSON Pointer is a string of tokens separated by / characters, where each token references a key in an object or an index in an array. Special characters ~ and / are escaped as ~0 and ~1 respectively. An empty string "" references the document root. This syntax provides a deterministic, unambiguous way to address any node in a deeply nested legal JSON structure, such as a specific clause within a contract.

04

Idempotent Patch Application

A well-formed JSON Patch is deterministic and idempotent when applied to the same source document. Applying the identical patch multiple times to the same initial state always produces the same final state. However, applying a patch to an already-patched document is not guaranteed to be safe without a test operation. For legal document versioning, this means a patch generated from a diff between Version A and Version B can be reliably applied to any copy of Version A to recreate Version B exactly.

05

Error Handling Semantics

If an operation fails, the server MUST NOT apply any subsequent operations in the patch and must return an appropriate error. Common failure modes include:

  • Test failure: The value at the path does not match the expected value.
  • Invalid path: The path references a non-existent location for a remove or replace.
  • Path collision: An add operation targets a path that already exists. This strict error model allows a client to use a test operation as an optimistic concurrency check, ensuring the document hasn't been modified by another party since the patch was generated.
06

Efficient Delta Transmission

Instead of transmitting an entire modified legal document, a client sends only the compact patch. For example, changing a single liability cap value from $1,000,000 to $2,000,000 in a 50KB contract requires transmitting only a few hundred bytes: [{ "op": "replace", "path": "/clauses/12/liabilityCap/amount", "value": 2000000 }]. This bandwidth efficiency is essential for high-frequency contract negotiation platforms and real-time collaborative redlining tools.

JSON PATCH RFC 6902

Frequently Asked Questions

Clear, technical answers to the most common questions about the JSON Patch format, its operations, and its application in precise, programmatic document modification.

JSON Patch is a standard format defined by RFC 6902 for describing a sequence of operations to apply to a target JSON document. It works by defining a JSON array of operation objects, each specifying an op (operation type), a path (a JSON Pointer to the target location), and a value (for add, replace, and test operations). Instead of transmitting an entire modified document, a client sends only the delta, a compact list of changes. The server then applies these operations atomically in order. If any operation fails, the entire patch fails, ensuring the document remains in a consistent state. This is foundational for RESTful APIs implementing the PATCH HTTP method and is critical in legal tech for applying precise, auditable modifications to structured contract data without ambiguity.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.