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

Feature request: JSON.stringify(), JSON.parse() #258

Open
apenneb opened this issue Jul 21, 2014 · 8 comments
Open

Feature request: JSON.stringify(), JSON.parse() #258

apenneb opened this issue Jul 21, 2014 · 8 comments

Comments

@apenneb
Copy link

apenneb commented Jul 21, 2014

ECMAScript 5 added JSON.stringify() and JSON.parse(), which ECMAScript 3- did not have built-in.

As a workaround, we can use these example functions in json2.js. (The old homepage for json2 is dead, but the script still lives in content distribution networks.)

http://cdnjs.com/libraries/json2

@hazzik
Copy link
Contributor

hazzik commented Jul 23, 2014

👎 Why do we need another polyfill if we can use either JSON2 or JSON3?

@ljharb
Copy link
Member

ljharb commented Jul 23, 2014

This should stay open, as it's a genuine question. Anything that's in the ES5 spec that can be made to work in ES3 should be strongly considered for the shim.

@Krinkle
Copy link
Contributor

Krinkle commented Jul 25, 2014

Assuming they both implement the parse and stringify methods accurately and in an acceptable manner performance wise, I'd recommend JSON3 because 1) it doesn't add non-standard toJSON methods to the Boolean, Number, and String prototypes; and 2) It makes use of the toJSON and toISOString methods on Date objects when available (especially useful considering those are covered by es5-shim when there is no native one or the native one is non-compliant).

@nagaozen
Copy link

Maybe adding a note in the README suggesting json2.js from douglascrockford/JSON-js is enough, since it keep getting security updates and is ES3 compatible. I see no reason to put more man power behind a code that is already well supported. Or maybe using git submodules...

@Xotic750
Copy link
Contributor

Xotic750 commented Nov 8, 2015

I would like to see these in es5-shim, json2 is not standards compliant (I have tests available) and it makes no effort to check the environment other than for truthy/falsy existence. json3 goes a step further and does perform checking and tries to be standards compliant, so this would be the one I'd go for. So, I guess the main reason is that it would be nice to have all the es5-shims in one rather than load multiple files, just a preference. :)

@ljharb
Copy link
Member

ljharb commented Nov 8, 2015

One file vs multiple files is a build pipeline concern - you should be using browserify/webpack anyways in 2015. If there doesn't exist an ES5-compliant JSON shim, then that's a great reason to build one and link to it from here, but it'd likely be too large to include in es5-shim - if json3 is compliant, let's close this by adding a note + link to the README.

@Xotic750
Copy link
Contributor

Xotic750 commented Nov 8, 2015

I'm fine with that.

@Xotic750
Copy link
Contributor

Been taking a closer look at JSON3, and there is some really good work over there, however there are things that I'm not so enthralled by and I see a fair amount of repetition of what has been achieved here in es5-shim (though I'm not convinced that it is to the same standard of breadth and accuracy). While I would still use it over JSON2, my feeling is that I would like to see it integrated here, it all feels correct to be here. I'd estimate about 500 lines of code (JSON3 is 900, with all the repeated work, line spaces and all the comments), and then the tests. Maybe they could be convinced to submit their work to es5-shim, or I'd be willing to work with you to port it over (or even JSON2). I believe I have most, if not all, of the tests already in the format for this project (those I could submit to you fairly quickly).

Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 18, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 18, 2015
es-shims#258

Ported the latest JSON3 test suite.
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 18, 2015
es-shims#258

Ported the latest JSON3 test suite.
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 18, 2015
es-shims#258

Ported the latest JSON3 test suite.

Jasminize.
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 18, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 18, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 18, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 19, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 19, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 19, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 19, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Nov 19, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Dec 9, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Dec 20, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Dec 27, 2015
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Jan 26, 2016
Xotic750 pushed a commit to Xotic750/es5-shim that referenced this issue Jan 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants