Starcounter-Jack / JSON-Patch

Lean and mean Javascript implementation of the JSON-Patch standard (RFC 6902). Update JSON documents using delta patches.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

replace incorrectly adds value when target location does not exist

rybesh opened this issue · comments

Section 4.3 of RFC6902 says:

The target location MUST exist for the operation to be successful.

But fast-json-patch incorrectly does an add instead of failing in this situation:

var fastJsonPatch = require("fast-json-patch")
var document = { foo: "bar" };
var patch = [
  { op: "replace", path: "/biz", value: "baz" },
];
document = fastJsonPatch.applyPatch(document, patch).newDocument;

The result is:

{biz: "baz", foo: "bar"}