Description
Diffson appears to interpret numeric JSON Pointer tokens as array indexes when parsing the pointer, rather than interpreting them according to the type of the JSON value encountered while evaluating the pointer.
This causes problems when JSON objects have numeric property names.
For example, given:
{
"shared": {
"a": 123
},
"100": {
"a": 456
}
}
this JSON Patch works:
[
{
"op": "copy",
"from": "/shared/a",
"path": "/100/b"
}
]
but the reverse direction fails:
[
{
"op": "copy",
"from": "/100/a",
"path": "/shared/a"
}
]
It looks like the 100 is interpreted as an array index instead of an object key.
Expected behavior
As I understand RFC 6901, a reference token itself does not distinguish between an object property and an array index. Its interpretation depends on the JSON value being traversed.
For example:
{
"0": "object value",
"array": [
"array value"
]
}
both of these pointers should be valid:
/0 should address the object member named "0", while /array/0 should address array index 0.
RFC 6901
Section 4 of RFC 6901 seems to specify that evaluation depends on the type of the current referenced value:
If the currently referenced value is a JSON object, the new referenced value is the object member with the name identified by the reference token.
Only if the currently referenced value is an array is the token interpreted as an array index.
Therefore, I would expect the distinction between an object key and an array index to be made during pointer evaluation rather than during pointer parsing.
Would you consider the current behavior a bug, or am I overlooking something in Diffson's interpretation of RFC 6901?
Description
Diffson appears to interpret numeric JSON Pointer tokens as array indexes when parsing the pointer, rather than interpreting them according to the type of the JSON value encountered while evaluating the pointer.
This causes problems when JSON objects have numeric property names.
For example, given:
{ "shared": { "a": 123 }, "100": { "a": 456 } }this JSON Patch works:
[ { "op": "copy", "from": "/shared/a", "path": "/100/b" } ]but the reverse direction fails:
[ { "op": "copy", "from": "/100/a", "path": "/shared/a" } ]It looks like the
100is interpreted as an array index instead of an object key.Expected behavior
As I understand RFC 6901, a reference token itself does not distinguish between an object property and an array index. Its interpretation depends on the JSON value being traversed.
For example:
{ "0": "object value", "array": [ "array value" ] }both of these pointers should be valid:
/0should address the object member named"0", while/array/0should address array index0.RFC 6901
Section 4 of RFC 6901 seems to specify that evaluation depends on the type of the current referenced value:
Only if the currently referenced value is an array is the token interpreted as an array index.
Therefore, I would expect the distinction between an object key and an array index to be made during pointer evaluation rather than during pointer parsing.
Would you consider the current behavior a bug, or am I overlooking something in Diffson's interpretation of RFC 6901?