JSON.stringify(undefined)

# Axel Rauschmayer (13 years ago)

... returns undefined. Shouldn’t it be "undefined"?

# Barry van Oudtshoorn (13 years ago)

I would assume that this is because the JSON grammar doesn't include "undefined" as an acceptable value -- JSON.stringify({foo:undefined}) returns "{}". Perhaps JSON.stringify(undefined) should, however, return "" -- in my view, this would make more sense.

# Tim Smart (13 years ago)

Calling JSON.stringify(undefined) is essentially the same as calling JSON.stringify()

null is a better representation of a 'empty' value.

Tim.

# Axel Rauschmayer (13 years ago)

Barry, Tim: Right, undefined is not valid JSON.