Skip to content
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

For V4 and V5, the apply results of the values that do not exist in replace are inconsistent. #204

Closed
xuoldkk opened this issue Apr 15, 2024 · 3 comments

Comments

@xuoldkk
Copy link

xuoldkk commented Apr 15, 2024

For V4 and V5, the apply results of the values that do not exist in replace are inconsistent.

V5: replace operation does not apply: doc is missing key: /load

v4: update success.

Is there any consideration for this? Check whether the configuration will be modified in V5.

Also, where are the differences between v4 and v5? Is there a link available?
image

What is the difference between the v5 and cmd/json directories?

func TestJsonPatchNewOrRep(t *testing.T) {
	originalFile :=
		[]byte(`{
    "allowedNfDomains": [
        "nfdomain"
    ]
}`)
	rawPatches := []byte(`[
    {
        "op": "replace",
        "path": "/load",
        "value": 30
    }
]`)

	patch, err := jsonpatch.DecodePatch(rawPatches)
	if err != nil {
		fmt.Println("cannot decode jsonpatch", err)
	}

	jsonPatched, err := patch.Apply(originalFile)
	if err != nil {
		fmt.Println("cannot apply jsonpatch: ", err)
	}

	fmt.Println(jsonPatched)
}

@xuoldkk
Copy link
Author

xuoldkk commented Apr 16, 2024

@evanphx Could you help me to answer it?

@evanphx
Copy link
Owner

evanphx commented Jan 27, 2025

v4 is legacy at this point, you should use v5.

@evanphx
Copy link
Owner

evanphx commented Jan 27, 2025

Replacing /load violates the RFC, that was a bug in v4 as I recall. You should use add here.

@evanphx evanphx closed this as completed Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants