➕JSON Patch Add Operation
Insert new values into JSON objects and arrays
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
Examples
Add to Object
Add a new property to an object
Patch:
Before:
After:
Add to Array
Append an item to an array
Patch:
Before:
After:
Insert at Index
Insert at a specific array position
Patch:
Before:
After:
Real World: Add a Nested Config Field
Add a new timeout inside an existing config object
Patch:
Before:
After:
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)
Working with arrays?
Appending with /-, inserting at an index, and why add never overwrites - every array rule with runnable examples.
Read: JSON Patch and Arrays →
Add Operation FAQ
Does add overwrite an existing value?
On an object, adding to a key that already exists replaces its value - but use replace for that, it signals intent. On an array, add never overwrites: it inserts before the index you give.
What happens if the parent path does not exist?
The operation fails and evaluation stops at that point. Every level of the path except the final key must already exist - create parent objects with earlier add operations first.
How do I append to an array without knowing its length?
End the path with /- instead of an index: { "op": "add", "path": "/items/-", "value": ... } always lands at the end.
Try the Add Operation Now
Use our free online JSON Patch generator to create add patches instantly
🚀 Open JSON Patch Generator