Coder Social home page Coder Social logo

Comments (5)

Starcounter-Jack avatar Starcounter-Jack commented on June 11, 2024

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.

beetaa avatar beetaa commented on June 11, 2024

Thank you Jack, but how about extending RFC6902 some more features? just call RFC6902-x

from json-patch.

tomalec avatar tomalec commented on June 11, 2024

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.

beetaa avatar beetaa commented on June 11, 2024

wow! nice answer, @tomalec , thank you very much! I completely agree with your points.

from json-patch.

tomalec avatar tomalec commented on June 11, 2024

@beetaa Could we close this issue?

Feel free to vote, and comment at #66.

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.