```add replace``` what's their distinct behavior i...
# ory-copilot
g
Copy code
add replace
what's their distinct behavior if you try to add what'sthere @chilly-king-10285
b
A message from kapa.ai
The
add
and
replace
operations are part of the JSON Patch document as defined by RFC 6902, which is used in Ory's API for patching projects and other entities. The
add
operation inserts a new item at the specified location in the JSON document. If the item already exists, the operation will replace it. The
replace
operation, on the other hand, changes the existing value at the specified location to a new value. If the item does not exist, the operation will fail. In the context of Ory's CLI commands, these operations are used to modify the configuration of various entities. The
--add
option adds a specific key to the configuration, while the
--replace
option replaces a specific key in the configuration. Please note that if you try to add a key that already exists using the
--add
option, it will replace the existing key. If you try to replace a key that does not exist using the
--replace
option, the operation will fail. Sources: - [Ory API Reference](https://www.ory.sh/docs/reference/api) - [Ory CLI Reference](https://www.ory.sh/docs/cli/ory-patch-oauth2-config#options)
g
will it add to the an array without specifying a pointer @chilly-king-10285
b
A message from kapa.ai
In the context of JSON Patch as defined by RFC 6902, the
add
operation will append to an array if you do not specify a pointer. If you specify a pointer that points to an existing array index, it will replace the item at that index. If you specify a pointer that points to an index beyond the current size of the array, the operation will fail. Here's an example: If you have the following JSON document:
Copy code
json {   "array": ["item1", "item2"] }
And you apply the following JSON Patch:
Copy code
json [   { "op": "add", "path": "/array", "value": "item3" } ]
The resulting JSON document will be:
Copy code
json {   "array": ["item1", "item2", "item3"] }
However, if you apply the following JSON Patch:
Copy code
json [   { "op": "add", "path": "/array/1", "value": "newItem2" } ]
The resulting JSON document will be:
Copy code
json {   "array": ["item1", "newItem2", "item2"] }
Please note that JSON Pointer notation is 0-indexed, so
/array/1
refers to the second item in the array. Source: [Ory API Reference](https://www.ory.sh/docs/reference/api)