📋JSON Patch Copy Operation
Duplicate values within JSON documents
RFC 6902
copy operation
What is the Copy Operation?
The copy operation duplicates the value at the "from" path to the "path" location. Unlike move, the source value remains in place. This is useful for creating backups or duplicating data.
Syntax
{ "op": "copy", "from": "/source/path", "path": "/destination/path" }
Examples
Copy Property
Duplicate a value to a new location
Patch:
{ "op": "copy", "from": "/original", "path": "/backup" }
Before:
{ "original": "data" }
After:
{ "original": "data", "backup": "data" }
Copy Nested Object
Duplicate an entire object structure
Patch:
{ "op": "copy", "from": "/template", "path": "/instances/0" }
Before:
{ "template": { "type": "default" }, "instances": [] }
After:
{ "template": { "type": "default" }, "instances": [{ "type": "default" }] }
Copy Array Element
Duplicate an item within an array
Patch:
{ "op": "copy", "from": "/items/0", "path": "/items/-" }
Before:
{ "items": ["original"] }
After:
{ "items": ["original", "original"] }
Common Use Cases
- Creating backup copies before modifications
- Duplicating templates or configurations
- Copying shared values to multiple locations
- Creating variations based on existing data
Best Practices
- Creates a deep copy of the source value
- Source path must exist
- Useful for templates and default values
Try the Copy Operation Now
Use our free online JSON Patch generator to create copy patches instantly
🚀 Open JSON Patch Generator