Closed joeltucci closed 10 years ago
OK well, the first issue I have is the diff code... While I have started working on it in order to understand it I am still not at ease with it, and I think it needs to be reworked. And it's been months since I've been touching it...
Apart from that I don't like the use of -
, since it is meant as a special reference token for additions/removals as defined by RFC 6902 (the last element of an array -- but I think you know that already). If such an operation is created, I'd rather the path
point to the array itself.
Finally, well, this goes outside the scope of RFC 6902 ;)
Which kind of calls for a v2; I am not against such an operation being added, far from it, but this would be yet another patch class. Ideally JsonPatch
would be made abstract, or even an interface, and one would choose between merge patch, rf6902 or an augmented rfc6902 with this operation included. And of course, there's the diff code...
Oops, I hadn't even thought about the RFC, sorry about that. I will go ahead and close this request but keep the code hanging around on my fork in case it ever comes in handy. Keep up the good work!
Currently operations to remove elements in an array are hard to read/write by hand. You either need to list the indexes you want to delete in reverse order or recalculate the indices on the fly, since the operations are applied in a stream and each operation is dependent on the previous(for instance deleting the first 2 elements requires 2 /0's). I would like to propose a block_remove operation that takes an array of indexes(all corresponding to the same position in the original array) and deletes them all at once. This could not only make the resulting diffs more compact, it could also help people who create them by hand.
I have created an example implementation here: https://github.com/joeltucci/json-patch/commit/341eb025a89ae4f17ae94694bb52a75a27ce0ce4
I didn't want to do this as a pull request since it may need to be significantly reworked, but if possible I would like to see this feature implemented.
Let me know if you have any questions/issues.