﻿# JSON Merge Patch and JSON Patch express different edits

JSON Merge Patch removes object members with null and replaces arrays as values; JSON Patch applies ordered operations, and HTTP PATCH alone does not identify either format.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-api-patch-merge-jsonpatch/
Language: en

## Identify the patch format before interpreting the body

A configuration API supports partial edits to an analysis source list. Sending an HTTP PATCH request does not by itself say whether the body is JSON Merge Patch or JSON Patch. The [HTTP PATCH specification](https://www.rfc-editor.org/rfc/rfc5789.html) distinguishes the method from accepted patch-document formats and provides `Accept-Patch` for advertising support. Use the documented media type and semantics rather than infer a format from a familiar-looking JSON payload.

## Read merge-patch null as member removal

The [Merge Patch specification](https://www.rfc-editor.org/rfc/rfc7396.html) describes an object-shaped example of changes. A null-valued member requests removal from the target object; it is not an ordinary instruction to retain that member with a null value. This makes the format less suitable for applications that need null as meaningful stored data. Leaving a member out of the patch also differs from including it with null, because the omission does not request its removal.

## Treat arrays according to the selected operation model

Merge Patch replaces an array as a whole value rather than editing selected elements inside it. [JSON Patch](https://www.rfc-editor.org/rfc/rfc6902.html) instead represents a sequence of operations such as add, remove and replace, with target paths. When the intention is to remove a particular source-list entry, choose the format that expresses the intended edit. Do not send a shortened array under the assumption that every patch format interprets it as an element-level difference.

## Preserve JSON Patch operation order

JSON Patch evaluates each operation against the result of its predecessor. Removing an array entry changes later positions, so operation order can change which source a later path addresses. A test operation can check the expected target value and fail evaluation when it does not match. [Task contracts](/journal/learn-codex-task-contract/) describe the final configuration; the patch document must express the transition to that configuration under its actual sequential rules.

## Review complete application and failure

HTTP PATCH requires atomic application of the set of changes: failure must not leave a partially modified representation exposed as the result. Preserve the server's actual outcome and inspect the intended resource state where needed. [Tool observations](/journal/learn-codex-tool-observation/) distinguish format rejection, failed operation and completed update. This gives a concrete explanation of the edit without treating every JSON object as a merge document, every null as a stored value or every ordered operation list as interchangeable with an example-shaped replacement.
