JSON empty string

json, string

Solution

Old question - but its the top result when you search for 'json stringify empty string' so I'll share the answer I found.

This appears to be a bug in certain versions of IE8, where empty DOM elements return a value which looks like an empty string, evaluates true when compared to an empty string, but actually has some different encoding denoting that it is a null value.

One solution is to do a replace whenever you call stringify.

`JSON.stringify(foo, function(key, value) { return value === "" ? "" : value });`

See also http://blogs.msdn.com/b/jscript/archive/2009/06/23/serializing-the-value-of-empty-dom-elements-using-native-json-in-ie8.aspx

Problem

why does the JSON.stringify-Function converts a string.Empty ("") to a "null"-String? The problem, why i'm not using: ``` JSON.parse(json, function(key, value) { if (typeof value === 'string') { if (value == 'null') return ''; return value; } }); ``` ...is, if somebody really write "null" (is very unlikely, but possible), i have a problem to... thank for each answer!

Original source

Related problems