Add support for JSON Patch
This is a quick stab at JSON Patch support in py_yyjson. Creating this PR for input and to keep upstream in sync with py_yyjson (https://github.com/TkTech/py_yyjson/pull/5).
Some things that are missing:
-
test, since there's currently no easy way to recursively compareyyjson_mut_val's -
-to indicate end-of-array. - Error reporting (just pass/fail)
- C tests. It's currently tested in the high-level Python tests (https://github.com/TkTech/py_yyjson/pull/5/files#diff-78e792cfafc71ca614966d5be40f70098bf25e7ef39acece8692f691102db801R67)
Things missing from the yyjson api that I ran into:
-
yyjson_mut_val_cmp()- deep comparison of values, which would make implementing features liketesttrivial. -
yyjson_mut_obj_remove() that takes aconst char *` instead of requiring creating a key (and thus wasting memory since we can't reclaim it). -
yyjson_mut_obj_move()andyyjson_mut_arr_move(), which allow moving a value between objects or arrays within the same document (removes the need to make copies). -
yyjson_val_mut_copy()that takes ayyjson_val_mut, which is required to move/copy values. Currently only ayyjson_valversion exists.
Hi @TkTech, curious as to what that status is on this PR and if you were going to come back to it.
@tristan957 I'm currently a bit too busy with work to get around to finishing this. There's not much left to do, and the missing facilities (like recursive equality to implement test) have been added in the meantime, so this PR can become slimmer and more complete.
Feel free to hijack this PR :)
The JSON Patch support has been added to the master branch.
Thanks! I've swapped to using your implementation of JSON Patch and JSON Merge-Patch here. Working well so far :+1:
@ibireme I believe you're using the examples from the RFC for your tests. In case it's of any use, py_yyjson is testing against the "conformance" test suite found here, https://github.com/json-patch/json-patch-tests/blob/master/tests.json in https://github.com/TkTech/py_yyjson/pull/7/commits/3e154c122ad03a8b411b6c4c2ea9530ef4dd7df5 and yyjson's implementation passes perfectly :+1: