miketalbot/js-coroutines

stringifyAsync includes keys with value `undefined', which is different from JSON.stringify

Opened this issue · 0 comments

Describe the bug

When stringifying an object using stringifyAsync, there is a different hanlding of undefined values than with JSON.stringify

To Reproduce

const object = {
    'foo': 'foo',
    'bar': undefined
}
const strAsync = (await stringifyAsync(object)).toString()
// result: {"foo":"foo","bar":null}
const str = JSON.stringify(object)
// result: {"foo":"foo"}

Note that the undefined value bar does not exist in the output of JSON.stringify, while it is null in the output of stringifyAsync.

Expected behavior

Since the documentation of stringifyAsync does not list any specific behaviour, I would have expected it to have the same behaviour as JSON.stringify and to not include keys with value undefined in the serialized string.

Environments

Tested on node 18.15.0 on Linux and Chrome 112.0.5615.138 on Windows