# JSON patch diff

`json-patch-diff` · version 1.0.0 · JSON & JSONL · free, no key needed

Generate a deterministic RFC 6902 patch from two JSON documents; returns the ordered patch operations.

**Use when you need to: generate a JSON patch between documents · diff two JSON values as RFC 6902 · create patch operations to transform JSON.**

## Decide before calling

Read the [versioned contract](/v1/tools/json-patch-diff/versions/1.0.0) and the supported scope below. Reuse `json-patch-diff@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `json-patch-diff@1.0.0` for generate a JSON patch between documents. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- generate a JSON patch between documents
- diff two JSON values as RFC 6902
- create patch operations to transform JSON
- turn before and after JSON into a patch
- build deterministic JSON patch
- compare JSON documents and return edits

## Not supported

- apply a JSON patch
- produce a textual unified diff

## Behavior

- Implements RFC 6902 (April 2013), Sections 4 and 5, with JSON Pointer syntax from RFC 6901 (April 2013), Sections 3 and 4.
- Inputs are JSON values; object keys are compared exactly and arrays are ordered. Processing is synchronous and deterministic.
- Limits are checked before or during bounded traversal; no network, filesystem, clock, locale, or randomness is used.

## Input

- `source` (any JSON value, required)
- `target` (any JSON value, required)

## Output

- `standard_version` (constant "RFC 6902 (April 2013); RFC 6901 (April 2013)", required)
- `patch` (array of object, required): max items 128

## Limits

- max input bytes: 65536
- max operations: 128
- max depth: 32
- max output bytes: 131072
- max iterations: 4096

## Example

Request input:

```json
{
  "source": {
    "a": 1
  },
  "target": {
    "a": 2
  }
}
```

Response:

```json
{
  "result": {
    "standard_version": "RFC 6902 (April 2013); RFC 6901 (April 2013)",
    "patch": [
      {
        "op": "replace",
        "path": "/a",
        "value": 2
      }
    ]
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "json-patch-diff",
  "version": "1.0.0",
  "input": {
    "source": {
      "a": 1
    },
    "target": {
      "a": 2
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/json-patch-diff/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"source":{"a":1},"target":{"a":2}}'
```

The machine-readable contract is at [/v1/tools/json-patch-diff/versions/1.0.0](/v1/tools/json-patch-diff/versions/1.0.0).

### CLI

```sh
node cli.mjs run json-patch-diff 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [JSON patch apply](/tools/json-patch-apply): Apply an RFC 6902 JSON Patch atomically; returns the document or the failing operation index and pointer.
- [JSON patch test only](/tools/json-patch-test-only): Evaluate only RFC 6902 test operations without modifying JSON; returns each test result and whether all passed.
- [JSON repair map offsets](/tools/json-repair-map-offsets): Map code point offsets between JSON text and its lexical repair, flagging offsets that fall inside an edit.
- [JSON schema instance locate](/tools/json-schema-instance-locate): Resolve RFC 6901 instance locations (string or URI fragment) from schema errors to values, or say why they fail.
- [JSON array align](/tools/json-array-align): Align two JSON arrays with duplicate-safe occurrence pairs and deterministic LCS tie-breaking.
- [JSON schema valid items filter](/tools/json-schema-valid-items-filter): Keep only the JSON records that pass (or fail) one Draft 2020-12 subset schema; returns kept records and index lists.
