📋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"] }

Real World: Reuse the Billing Address

Default the shipping address to the billing one

Patch:
{ "op": "copy", "from": "/billing/address", "path": "/shipping/address" }
Before:
{ "billing": { "address": { "city": "NYC" } } }
After:
{ "billing": { "address": { "city": "NYC" } }, "shipping": { "address": { "city": "NYC" } } }

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

Copy Operation FAQ

Does copy link the two values?

No. copy makes a deep, independent clone - changing the copy later does not affect the source, and vice versa.

What is the difference between copy and move?

copy keeps the source value in place; move deletes it. Use copy for defaults and templates, move for renames and restructuring.

What happens if the destination already exists?

The destination follows add semantics: on an existing object key the value is replaced, and the destination parent must exist.

Try the Copy Operation Now

Use our free online JSON Patch generator to create copy patches instantly

🚀 Open JSON Patch Generator