Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting value to undefined removes property #46

Open
danrot opened this issue May 8, 2019 · 5 comments
Open

Setting value to undefined removes property #46

danrot opened this issue May 8, 2019 · 5 comments

Comments

@danrot
Copy link

danrot commented May 8, 2019

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}
@jperasmus
Copy link

Looks like it is intentional:

if (value === undefined) delete obj[part]

@janl
Copy link
Owner

janl commented Jul 3, 2020

yeah, this is by design #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.

@jperasmus
Copy link

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?

@janl
Copy link
Owner

janl commented Nov 1, 2021

sure, all of this sounds good

@johnmiroki
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants