Skip to content

Replace for PATCH doesn't seem to be working as per rfc6902 #40

@binodluitel

Description

@binodluitel

I am trying to use replace and as per rfc6902 The target location MUST exist for the operation to be successful.
When I do that:

var payload = []byte(`[{"op":"replace", "path":"/first_name", "value":"Bond, James Bond"}]`)
var doc = []byte(`{"firstName":"John Doe"}`)

func main() {
	obj, err := jsonpatch.DecodePatch(payload)
	if err != nil {
		println(err.Error())
	}

	out, err := obj.Apply(doc)
	if err != nil {
		println(err.Error())
	}

	println(string(out))
}

I am getting

{"firstName":"John Doe","first_name":"Bond, James Bond"}

where I expected it to fail because doc do not have /first_name

If anyone can confirm it is a bug, I can open a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions