Skip to content

Commit 18ca8a6

Browse files
committed
Fixed bug on top level change
1 parent bd90f08 commit 18ca8a6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

jsondiff.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export default class JSONDiff {
4040
}
4141
generateObjDiff(oldObj=this.oldObj, newObj=this.newObj, path='', pushToArr=this.jsonPatch) {
4242
if (this.isEmpty(oldObj)) {
43-
pushToArr.push({op: "add", path: "/", value: newObj});
43+
pushToArr.push({op: "add", path: `${path ? path : '/'}`, value: newObj});
4444
} else if (this.isEmpty(newObj)) {
45-
pushToArr.push({op: "delete", path: "/"});
46-
this.setDelete('/');
45+
pushToArr.push({op: "delete", path: `${path ? path : '/'}`});
46+
this.setDelete(`${path ? path : '/'}`);
4747
} else {
4848
const oldKeys = this.getKeys(oldObj);
4949
const newKeys = this.getKeys(newObj);

0 commit comments

Comments
 (0)