epoberezkin / fast-json-stable-stringify

Deterministic JSON.stringify() - a faster version of @substack's json-stable-strigify without jsonify.
Other
285 stars 34 forks source link

String instances are transformed into objects #74

Open iplanwebsites opened 2 years ago

iplanwebsites commented 2 years ago

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.