Comments (11)
When is this getting merged/fixed? It's not working correctly with .NET Core's JSON Patch implementation, failing with this error: For operation 'add', the target location specified by path '/roles/1' was not found.
from json-patch.
RFC says:
The specified index MUST NOT be greater than the
number of elements in the array.
So it seems, even if it worked nice for our use cases, it's not a valid JSON-Patch :/
Thanks for reporting @danieldonev !
from json-patch.
You can make check if the element indedx is equal to the array.length-1, then finish with "/-" otherwise stick to the current implementation (in case the element HAS to be inserted in specific position)
var element = "test4";
var array = ["test0", "test1", "test2", "test3"]
array.push(element )
// the array.indexOf(element) will be 4;
//array.length will be 5
If(array.indexOf(element) === array.length-1){
// use "/-" instead of an index
}else{
//use the current implementation
}
from json-patch.
err.. my bad 2
is equal to "the number of elements in array", so this patch seems to be valid as well.
@danieldonev, Is there any specific reason, why it does not work for you? As we aim to be super fast, every if needs to be considered as performance threat.
from json-patch.
Well, let`s imagine that you have JAVA RESTful API, you will be trying to add an element to an index which does not exist. In the case where you add an element to the JS array of 5 element the new one will be 6-th and the patch path will end with "/5" where the java array has also 5 elements but the last element has index 4 and you are trying to add it to index 5. it will throw an exception
from json-patch.
But I would say that's what standards are for. If Java implementation of JSON-Patch cannot process valid JSON-Patch, then this should be fixed on Java end.
from json-patch.
True. BUT - "If the "-" character is used to index the end of the array (see [RFC6901]), this has the effect of appending the value to the array." Since I am adding the new element at the end of the array it does not make sence to specify the index since i am not moving any of the existing elements.
from json-patch.
The vendor neutral JSON-Patch test suite uses both .../<number>
and ../-
to add elements at the end of the array. They seem to be equal choices.
I guess that a fix for that would be just a change in line https://github.com/Starcounter-Jack/JSON-Patch/blob/master/src/json-patch-duplex.ts#L189
For me switching to .../-
sounds like a potential performance improvement.
@tomalec would there be some potential implications for https://github.com/PuppetJs/JSON-Patch-OT?
from json-patch.
Actually it should support both. If the new element is added in specific position (is not at the end) is must use the /number. If it is at the end just use /- version of it
from json-patch.
Well, I'll check if it affect OT, as switching to more efficient solution is always a good idea.
However I cannot find a statement in spec that says it MUST be like that. I can see only implication it opposite direction. Maybe It can be discussed at json-patch spec issue tracker?
from json-patch.
from json-patch.
Related Issues (20)
- rrrr HOT 1
- Add performance comparison with jsondiffpatch
- Array patching, over empty elements.. HOT 2
- Any plans for a new release? HOT 1
- Maybe it's already discussed, but anyone think of how to patch array member in a more flexible approach?
- Release 3.1.1 request based on PR merged of #262 HOT 2
- Inaccurate documentation HOT 1
- Error index always 0? HOT 1
- Optional observe callback not called HOT 1
- applyPatch() validator index is not incrementing
- Backport fix for GHSA-8gh8-hqwg-xf34 to v2 HOT 5
- package.json should use `conditional exports`, else esm won't work inexplicitly HOT 1
- Node12+ import documentation incorrect
- Documentation for `generate` mentions wrong signature
- auto add tests to "add/remove" operations like for "replace"
- Mixing default exports and named exports breaks parcel HOT 2
- Attempting to use if mirror has a toJSON and object does not breaks HOT 2
- applying a replace patch is inconsistent with path="" and path="/"
- Is the project dead ? HOT 1
- 3.1.1 commonjs delivery corrupted on npm HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-patch.