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

How to get test patch? #98

Open
michaelrice opened this issue Jun 21, 2019 · 3 comments
Open

How to get test patch? #98

michaelrice opened this issue Jun 21, 2019 · 3 comments

Comments

@michaelrice
Copy link

Given:

d1 = {1: "a", 2: "b"}
d2 = {1: "b", 2: "v"}
patch = jsonpatch.make_patch(d1, d2)
patch.to_string()
'[{"value": "b", "op": "replace", "path": "/1"}, {"value": "v", "op": "replace", "path": "/2"}]'

How can I get the patch that would have test instead of replace?

@Xronophobe
Copy link

@michaelrice
Copy link
Author

@Xronophobe Im not sure I understand what you mean? My use case is to have jsonpatch generate a patch that I send to a remote API in a PATCH operation. Right now Im only able to get a patch object that has replace but Id like to get the patch to have test in it as well so I can submit it first to make sure the API would be happy, then if I get a success response from my test patch I can follow up with another call that has the real patch in it with replace

@jschristensen
Copy link

The API that I'm working against also requires a test operation on the existing value before any other operation can take place. As a work-around for this, I switched around the old and new document and changed the "op" to "test" on the resulting patch document. Maybe there's a smarter way?

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

3 participants