Comments (5)
No. The JSON Patch behavior is standardized in RFC6902, so I'm afraid we cannot change the way replace patches work.
Sent from my iPhone
On 23 Mar 2015, at 11:14, beetaa [email protected] wrote:
assume that there's an object like:
var obj_src = {
name: "jone",
city: "Sydney",
pets: [
{nickname: "volo", category: "dog", age: "3"},
{nickname: "wabit", category: "cat", age: "5"},
{nickname: "moaoaa", category: "tiger", age: "1"},
{nickname: "gofast", category: "lion", age: "3"}
]
}
if pets' nickname is unique, can I use patch like {op: "replace", path: "/pets[nickname=wabit]/age", value: "9"} to alter wabit's age instead using {op: "replace", path: "/pets/1/age", value: "9"} because sometimes I don't know the array order.—
Reply to this email directly or view it on GitHub.
from json-patch.
Thank you Jack, but how about extending RFC6902 some more features? just call RFC6902-x
。
from json-patch.
I believe we should serve tiny lib that do one job, and do it well and blazing fast ;)
With tiny support of jsonpointer #66, and native Array.prototype.filter
I would suggest something like
var patch = [{op: "replace", path: "/age", value: "9"}];
var cssFilter = function(selector){
return function(el, index){
// do some nice CSS selector style filtering, or anything you want
}
}
jsonpatch.apply( jsonpointer( obj_src, "/pets").filter(cssFilter("[nickname=wabit]")), patch);
Or write completely separated concept of JSON-CSS-Pointer (extended https://tools.ietf.org/html/rfc6901), and then use it like
var cssPatch = [{op: "replace", path: "/pets[nickname=wabit]/age", value: "9"}];
jsonpatch.apply( obj_src, jsonCSSSelectorToPointer( obj_src, cssPatch ));
from json-patch.
wow! nice answer, @tomalec , thank you very much! I completely agree with your points.
from json-patch.
@beetaa Could we close this issue?
Feel free to vote, and comment at #66.
from json-patch.
Related Issues (20)
- Inefficient patch encoding when prepending to arrays HOT 2
- 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 ?
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.