JSON Patch

JSON Patch Online Examples

Real-world scenarios to understand JSON Patch operations. Click any example to try it live with our JSON patch online tool and see the patch results instantly.

User Profile Update

Updating user information with new email and preferences

Original JSON:

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

Updated JSON:

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

Click to open the main tool with this data pre-loaded.
See the generated JSON Patch instantly!

Shopping Cart Operations

Adding items and applying discounts to a shopping cart

Original JSON:

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

Updated JSON:

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

Click to open the main tool with this data pre-loaded.
See the generated JSON Patch instantly!

Configuration Management

Updating application configuration for production deployment

Original JSON:

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

Updated JSON:

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

Click to open the main tool with this data pre-loaded.
See the generated JSON Patch instantly!

Using JSON Patch in Your Code

JavaScript (Node.js/Browser)

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

Python

import jsonpatch # Generate patch patch = jsonpatch.make_patch(old_obj, new_obj) # Apply patch new_obj = jsonpatch.apply_patch(old_obj, patch)

Want to create your own JSON patches with our online tool?

🚀 Open JSON Patch Online Tool