2 ms·
I can't help thinking that [ { "op": "replace", "path": "/baz", "value": "boo" }, { "op": "add", "path": "/hello", "value": ["world"] }, { "o
by jameshart 12y ago
I can't help thinking that
[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo"}
]
would be better described as
value["baz"] = "boo";
value["hello"] = ["world"];
delete value["foo"];
Why go to the trouble of defining your grammar as a strict subset of JSON documents, which are themselves written using a strict subset of JavaScript syntax, when you could just limit yourself instead to the strict subset of JavaScript syntax that encapsulates the operations you actually want to perform?
- Morhaus 12y agoBecause it's much easier to implement?
- jameshart 12y agoTo support this JSON patch format, you've got to implement a system which validates that all the array entries are in a valid format, securely interprets the 'path' attribute, and processes the rules according to a specification which may or may not cover every edge case To support my approach, you need to validate that each line uses a strict subset of JavaScript, then securely evaluate each one according to the well defined rules of JavaScript. Both have basically the same essential complexity - not sure I see why the JSON format patch is inherently 'easier' to work with.
- derefr 12y agoYou can write a simple library to apply a valid JSON patch in any language. Your method basically requires a JavaScript engine.