JSON Patch Examples

Real-world scenarios demonstrating JSON Patch operations. Click any example to load it into the generator and see results instantly.

User Profile Update

Common

Updating user information with new email and preferences.

Source JSON

{
  "id": 123,
  "name": "John Doe",
  "email": "john@example.com",
  "age": 25,
  "preferences": {
    "theme": "light",
    "notifications": true
  }
}

Target JSON

{
  "id": 123,
  "name": "John Smith",
  "email": "john.smith@example.com",
  "age": 26,
  "preferences": {
    "theme": "dark",
    "notifications": true,
    "language": "en"
  }
}

Click to load this example into the generator

Try Live

Shopping Cart Operations

E-commerce

Adding items and applying discounts to a shopping cart.

Source JSON

{
  "items": [
    {
      "id": "item1",
      "name": "Laptop",
      "price": 999
    },
    {
      "id": "item2",
      "name": "Mouse",
      "price": 25
    }
  ],
  "total": 1024,
  "discount": 0
}

Target JSON

{
  "items": [
    {
      "id": "item1",
      "name": "Laptop",
      "price": 999
    },
    {
      "id": "item2",
      "name": "Mouse",
      "price": 25
    },
    {
      "id": "item3",
      "name": "Keyboard",
      "price": 75
    }
  ],
  "total": 1099,
  "discount": 10
}

Click to load this example into the generator

Try Live

Configuration Management

DevOps

Updating application configuration for production deployment.

Source JSON

{
  "database": {
    "host": "localhost",
    "port": 5432,
    "ssl": false
  },
  "cache": {
    "enabled": true,
    "ttl": 3600
  },
  "features": [
    "auth",
    "logging"
  ]
}

Target JSON

{
  "database": {
    "host": "prod-db.company.com",
    "port": 5432,
    "ssl": true,
    "pool_size": 20
  },
  "cache": {
    "enabled": true,
    "ttl": 7200
  },
  "features": [
    "auth",
    "logging",
    "analytics"
  ]
}

Click to load this example into the generator

Try Live

Using JSON Patch in Your Code

Get started with JSON Patch in JavaScript or Python in just a few lines.

JavaScript
Python
import { compare, applyPatch } from 'fast-json-patch'; // ESM
// Generate patch
const patch = compare(oldObj, newObj);
// Apply patch
const result = applyPatch(oldObj, patch).newDocument;

Ready to create your own patches?

Use our free online tool to generate, validate, and test JSON Patch operations.

Open JSON Patch Generator