Coder Social home page Coder Social logo

Comments (3)

warpech avatar warpech commented on June 11, 2024

The easiest is to reverse the order of remove operation if possible:

[
    { "op": "remove", "path": "/foo/1" },
    { "op": "remove", "path": "/foo/0" }
]

I will take a look at the spec if it describes this situation.

from json-patch.

warpech avatar warpech commented on June 11, 2024

Though it is not normative, the current behaviour of the apply method passes the test case in https://github.com/json-patch/json-patch-tests/blob/master/tests.json#L279:

{ "comment": "test repeated removes",
      "doc": [1, 2, 3, 4],
      "patch": [{ "op": "remove", "path": "/1" },
                { "op": "remove", "path": "/2" }],
      "expected": [1, 3] },

So it can be assumed that other implementations work the same way.

from json-patch.

warpech avatar warpech commented on June 11, 2024

RFC 6902 says it clear.

  1. Document Structure

Operations are applied sequentially in the order they
appear in the array. Each operation in the sequence is applied to
the target document; the resulting document becomes the target of the
next operation.

4.2. remove

If removing an element from an array, any elements above the
specified index are shifted one position to the left.

Therefore, I am closing this ticket as the current implementation conforms to the spec.

Thanks for reporting, hopefully you can reverse the array of operations in your code.

from json-patch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.