-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace op should error out if path doesn't exist #119
Comments
Looking at the json-patch code, it looks like there is an error check to catch above condition but error returned is always nil. _, ok := con.get(key)
if ok != nil {
return errors.Wrapf(ErrMissing, "replace operation does not apply: doc is missing key: %s", path)
} and the get func is func (d *partialDoc) get(key string) (*lazyNode, error) {
return (*d)[key], nil
} I think we can check the existence of key in the map first and accordingly return the error. |
This has been reported a couple of times, e.g. #78 I'm myself using an older fork of this repository and |
I have checked this since my last comment and v5 behaves correctly. |
Hi,
As per Json RFC, path must exist for the operation to be successful.
Refer this section from the RFC doc:
But right now if the path doesn't exist, then json-patch doesn't error out and instead
add
the specified value at the given path.Eg:
output -->
{"age":24,"height":1.23,"name":"John"}
Here
/height
path doesn't exist but replace operation instead of throwing error, adds height field in the json doc.I'm not sure if this is the required behaviour or error is masked intentionally not to break things if path doesn't exist.
The text was updated successfully, but these errors were encountered: