🔄JSON Patch Replace Operation
Update existing values in JSON documents
RFC 6902
replace operation
What is the Replace Operation?
The replace operation updates the value at the specified path with a new value. The path must point to an existing value - use add for creating new values. This is semantically equivalent to remove followed by add.
Syntax
{ "op": "replace", "path": "/path/to/target", "value": <new value> }
Examples
Replace Primitive
Update a simple value
Patch:
{ "op": "replace", "path": "/age", "value": 30 }
Before:
{ "name": "John", "age": 25 }
After:
{ "name": "John", "age": 30 }
Replace Object
Replace an entire nested object
Patch:
{ "op": "replace", "path": "/address", "value": { "city": "LA" } }
Before:
{ "address": { "city": "NYC", "zip": "10001" } }
After:
{ "address": { "city": "LA" } }
Replace Array Element
Update a specific array item
Patch:
{ "op": "replace", "path": "/items/0", "value": "updated" }
Before:
{ "items": ["old", "b", "c"] }
After:
{ "items": ["updated", "b", "c"] }
Common Use Cases
- Updating user profile information
- Changing configuration values
- Modifying prices or quantities
- Updating status fields
Best Practices
- Path must exist - use add for new values
- Replaces the entire value, including nested structures
- Use for clarity over add when updating existing values
Try the Replace Operation Now
Use our free online JSON Patch generator to create replace patches instantly
🚀 Open JSON Patch Generator