This is related to what #10 addresses. That issue fixes when arrays don't exist to begin with but there is also the problem that when you set a value using force = true, and the path leads through an array element that doesn't exist yet, you get the final value inserted into the array rather than objects being created as expected.
ptr = require('json-ptr')
a = {
Foo: []
}
p = ptr.create('/Foo/0/Bar/Baz');
// Succeeds but with incorrect results.
p.set(a, 5, true);
// a is now { Foo: [5] }
// a should be
// {
// Foo: [
// {
// Bar: {
// Baz: 5
// }
// }
// ]
// }
console.log(a);
p = ptr.create('/Foo/Bar/Baz');
b = {
Foo: {}
}
p.set(b, 5, true);
// Works as you'd expect.
// b is now
// {
// Foo: {
// Bar: {
// Baz: 5
// }
// }
// }
console.log(b);
This is related to what #10 addresses. That issue fixes when arrays don't exist to begin with but there is also the problem that when you set a value using force = true, and the path leads through an array element that doesn't exist yet, you get the final value inserted into the array rather than objects being created as expected.