stefankoegl / python-json-patch

Applying JSON Patches in Python
https://python-json-patch.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
434 stars 94 forks source link

Allow custom JSON pointer class #114

Closed tzoiker closed 3 years ago

tzoiker commented 3 years ago

@stefankoegl It would be nice to be able to pass a custom implementation of the JSON pointer.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.1%) to 65.953% when pulling eca4f8ab337b8ca8e9db5d0d0d81f536d77fbd7d on tzoiker:feature/custom-pointer into 24b5e86dd66824dce232ea07e95d39a67b1dd735 on stefankoegl:master.

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.05%) to 64.989% when pulling 124eb76c09136aef56618e7347230f981edd51c3 on tzoiker:feature/custom-pointer into 4fe5c2c6a1e082fd1bacd36d8862d3a4d968f20b on stefankoegl:master.

tzoiker commented 3 years ago

@stefankoegl is it possible to accept soon? I want to use it in another project and avoid even temporary copy-pasting.

tzoiker commented 3 years ago

LGTM, would you mind adding more tests for custom Pointer which is not extended from python-json-pointer? Just for curiosity, can't python-json-pointer meet your current requirment?

Added a toy example. The idea was to at least be able to extend (or replace with the same, but custom implementation in C or whatever). In my particular case, I wanted to add an extension (out of spec, obviously) that allows to dynamically match array indexes based on the nested values of array elements (something like /@foo="bar"/val instead of /1/val for [{"foo": "baz", "val": 0}, {"foo": "bar", "val": 1}}]).

Alanscut commented 3 years ago

Nice work! it will make this lib more flexiable.

stefankoegl commented 3 years ago

@tzoiker, looks good. Please revert the change of version number - that will be done when a new release is prepared.

Could you please also briefly describe your use case?

tzoiker commented 3 years ago

@tzoiker, looks good. Please revert the change of version number - that will be done when a new release is prepared.

Could you please also briefly describe your use case?

Described it in this comment https://github.com/stefankoegl/python-json-patch/pull/114#issuecomment-728773802

Hmm, for some reason coverage decreased after I reverted the package version.

stefankoegl commented 3 years ago

I have just released v1.27 which inlcudes this PR. Thanks for the contribution!