Skip to content

Request for adding a block remove operation for arrays #9

Closed

Description

@joeltucci

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: joeltucci@341eb02

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.

Activity

  1. fge commented on Mar 24, 2014

    @fge
    Collaborator

    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...

  2. joeltucci commented on Mar 24, 2014

    @joeltucci
    ContributorAuthor

    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!

  3. added a commit that references this issue on Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions