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

Add option to strip undefined values off object as JSON does #106

Closed
willium opened this issue Mar 1, 2020 · 1 comment · Fixed by #107
Closed

Add option to strip undefined values off object as JSON does #106

willium opened this issue Mar 1, 2020 · 1 comment · Fixed by #107
Labels

Comments

@willium
Copy link

willium commented Mar 1, 2020

In JSON, undefined values stripped off the object

> JSON.parse(JSON.stringify({a: undefined}))
{}
> JSON.parse(JSON.stringify({a: undefined})).a
undefined

and undefined values in arrays are converted to null

It would be great if there were some option that removed undefined props at encode time.

@gfx
Copy link
Member

gfx commented Mar 3, 2020

It sounds good to reduce the size of payloads, but it will consume more time in encoding because MessagePack's map type has a "size" data before its contents, so the encoder must count the number of entries to encode. So I'll add it but won't make it the default.

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

Successfully merging a pull request may close this issue.

2 participants