Stumbled upon this one when attempting to use this library to normalize API outputs.
I'm not sure if it's an expected behavior.
stringify({ a: new String('hello') })
// {"a":{"0":"h","1":"e","2":"l","3":"l","4":"o"}}
While using JSON.stringify({ a: new String('hello') }) returns {"a":"hello"}.
String instances, created using new String() shouldn't usually be returned in place of strings, but some poor function in some codebases returns string instances using new String. For these cases, it'd be nice if the output would produce symmetrical rendering of Strings than JSON.stringify() for user looking for a drop-in replacement.
Stumbled upon this one when attempting to use this library to normalize API outputs. I'm not sure if it's an expected behavior.
While using
JSON.stringify({ a: new String('hello') })
returns{"a":"hello"}
.String instances, created using
new String()
shouldn't usually be returned in place of strings, but some poor function in some codebases returns string instances using new String. For these cases, it'd be nice if the output would produce symmetrical rendering of Strings than JSON.stringify() for user looking for a drop-in replacement.