Setting value to undefined removes property
I am setting a value of undefined on an object using your library, and this removes the property completely. I would like to keep the property and really set its property to undefined.
I also put an example here:
const a = {value: 5};
jsonpointer.set(a, 'value', undefined);
console.log(a); // outputs something like {}, but I would like to have {value: undefined}
Looks like it is intentional: https://github.com/janl/node-jsonpointer/blob/2a9875e14983712fbde05b4710fcdc53d4d6b575/jsonpointer.js#L42
yeah, this is by design https://github.com/janl/node-jsonpointer/pull/27
I’d accept a PR that implements set(obj, pointer, value, {allowUndefinedValue: true}). Bonus points for a way to instantiate a set fun that has that option bound to it for each invocation.
Please file a PR directly.
What about exposing a new setup or settings function that can be called to globally apply this and possible future config options?
jsonpointer.settings({ allowUndefinedValue: true })
Is this something you would be interested in?
sure, all of this sounds good
One thing to note is there is NOT undefined in JSON, while undefined is a valid value in JavaScript object. So for [1, undefined, 2] in JavaScript, when it's converted to JSON, it becomes [1, null, 2], which may have undesired effect.