➕JSON Patch Add Operation
Insert new values into JSON objects and arrays
RFC 6902
add operation
What is the Add Operation?
The add operation inserts a new value into a JSON document at the specified path. If the path points to an existing array element, the new value is inserted before that element. If the path ends with a hyphen (-), the value is appended to the array.
Syntax
{ "op": "add", "path": "/path/to/target", "value": <any JSON value> }
Examples
Add to Object
Add a new property to an object
Patch:
{ "op": "add", "path": "/email", "value": "john@example.com" }
Before:
{ "name": "John" }
After:
{ "name": "John", "email": "john@example.com" }
Add to Array
Append an item to an array
Patch:
{ "op": "add", "path": "/items/-", "value": "new item" }
Before:
{ "items": ["a", "b"] }
After:
{ "items": ["a", "b", "new item"] }
Insert at Index
Insert at a specific array position
Patch:
{ "op": "add", "path": "/items/1", "value": "inserted" }
Before:
{ "items": ["a", "b", "c"] }
After:
{ "items": ["a", "inserted", "b", "c"] }
Common Use Cases
- Adding new fields to user profiles
- Inserting items into shopping carts
- Appending log entries
- Adding new configuration options
Best Practices
- Use "/-" to append to arrays without knowing the length
- The parent path must exist before adding nested values
- Adding to an existing path will replace the value (use replace for clarity)
Try the Add Operation Now
Use our free online JSON Patch generator to create add patches instantly
🚀 Open JSON Patch Generator