blakeembrey/javascript-stringify

Stringify does not JSON stringify

samuelt1 opened this issue · 1 comments

If you stringify an object it will not JSON stringify it:

s = require('javascript-stringify')

console.log(JSON.stringify({hi:'howdy'}))
console.log(s.stringify({hi:'howdy'}))

outputs:

{"hi":"howdy"}
{hi:'howdy'}

This means it is not a real stringifyer. it is a make human readable stringifyer. If you try to run JSON.parse(s.stringify({hi:'howdy'})) it will throw an error Unexpected token h in JSON at position 0

This is not a JSON stringifier, this is a JavaScript stringifier. As the README notes, the intent is to generate valid JavaScript not JSON. Otherwise you could just use JSON.stringify, as you have noted.