Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify does not JSON stringify #32

Closed
samuelt1 opened this issue Apr 2, 2020 · 1 comment
Closed

Stringify does not JSON stringify #32

samuelt1 opened this issue Apr 2, 2020 · 1 comment
Labels

Comments

@samuelt1
Copy link

samuelt1 commented Apr 2, 2020

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

@blakeembrey
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants