
JSON.stringify(null) returns the string null.
JSON.stringify(undefined) returns the value undefined. Shouldn't it return the string undefined?
Parsing the value undefined or the string undefined gives a SyntaxError.
Could someone explain why JSON chokes on undefined and how to get around it when stringifying / parsing values?
JSON.stringify( myvar ? myvar : "*ERROR*" )JSON.stringify( myvar || "*ERROR*" )undefinedisn't recognized by JSON.JSON.stringify({ foo: 'bar', baz: undefined }) === '{"foo":"bar"}'.undefinedis also how you skip values with thereplacer.JSON.stringify(undefined)it the same as callingJSON.stringify()(i.e. without any arguments).