Replace appends a "replace" operation to patch. > The "replace" operation replaces the value at the target location > with a new value. > > The target location MUST exist for the operation to be successful.
(path ...string)
| 85 | // > |
| 86 | // > The target location MUST exist for the operation to be successful. |
| 87 | func (patch *JSON6902) Replace(path ...string) func(value any) *JSON6902 { |
| 88 | i := len(*patch) |
| 89 | f := func(value any) *JSON6902 { |
| 90 | (*patch)[i] = map[string]any{ |
| 91 | "op": "replace", |
| 92 | "path": patch.pointer(path...), |
| 93 | "value": value, |
| 94 | } |
| 95 | return patch |
| 96 | } |
| 97 | |
| 98 | *patch = append(*patch, f) |
| 99 | |
| 100 | return f |
| 101 | } |
| 102 | |
| 103 | // Bytes returns the JSON representation of patch. |
| 104 | func (patch *JSON6902) Bytes() ([]byte, error) { return patch.Data(nil) } |