We're experiencing when applying patches with JSON pointer escapes (~1') using fast-json-patch (3.0.0-1).
From what I read, JSON pointers need to have their slashes escaped:
Because the characters '~' (%x7E) and '/' (%x2F) have special
meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/'
needs to be encoded as '~1' when these characters appear in a
reference token.
OPERATION_PATH_UNRESOLVABLE: Cannot perform the operation at a path that does not exist
name: OPERATION_PATH_UNRESOLVABLE
index: 0
operation: {
"op": "replace",
"path": "/hello~1world",
"value": 42
}
tree: {
"hello/world": 0
}
at new PatchError (node_modules/fast-json-patch/commonjs/helpers.js:170:28)
....
name: 'OPERATION_PATH_UNRESOLVABLE',
index: 0,
operation: { op: 'replace', path: '/hello~1world', value: 42 },
tree: { 'hello/world': 0 }
}
Code:
let source = JSON.parse(`{ "hello/world": 0 }`)
let patch = JSON.parse(`[{"op":"replace","path":"/hello~1world","value":42}]`)
// This works:
console.log(fastJsonPatch.applyPatch(source, patch, false).newDocument)
// This fails with "OPERATION_PATH_UNRESOLVABLE":
fastJsonPatch.applyPatch(source, patch, true)
We're experiencing when applying patches with JSON pointer escapes (~1') using
fast-json-patch
(3.0.0-1).From what I read, JSON pointers need to have their slashes escaped:
Test data:
{"hello/world": 0}
[{"op":"replace","path":"/hello~1world","value":42}]
Result:
{"hello/world": 42}
(good)Code: