yyjson icon indicating copy to clipboard operation
yyjson copied to clipboard

Add support for JSON Patch

Open TkTech opened this issue 5 years ago • 2 comments

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 compare yyjson_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 like test trivial.
  • yyjson_mut_obj_remove() that takes a const char *` instead of requiring creating a key (and thus wasting memory since we can't reclaim it).
  • yyjson_mut_obj_move() and yyjson_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 a yyjson_val_mut, which is required to move/copy values. Currently only a yyjson_val version exists.

TkTech avatar Jan 01 '21 10:01 TkTech

Hi @TkTech, curious as to what that status is on this PR and if you were going to come back to it.

tristan957 avatar Sep 07 '22 21:09 tristan957

@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 :)

TkTech avatar Sep 08 '22 08:09 TkTech

The JSON Patch support has been added to the master branch.

ibireme avatar May 05 '23 17:05 ibireme

Thanks! I've swapped to using your implementation of JSON Patch and JSON Merge-Patch here. Working well so far :+1:

TkTech avatar May 09 '23 02:05 TkTech

@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:

TkTech avatar May 10 '23 07:05 TkTech