JSON 3: A modern JSON polyfill compatible with nearly all JavaScript platforms.
bestiejs.github.com
bestiejs.github.com
I agree that it shouldn't be called a polyfill.
It is a JS polyfill/shim/fallback for older browsers like IE 6 and 7 but also fixes/fills in gaps in support/consistency with modern browsers that have buggy implementations.
The use of the word "modern" in the description is to suggest it is more up-to-date than Crockford's aging/stale json2.js.
For what it's worth, I've created a fork of Kyle Simpson's `JSON.minify` project that uses a variation of the character-based parsing process in JSON 3: https://github.com/kitcambridge/JSON.minify/blob/master/mini... It's somewhat cumbersome to use, though, as it needs to be called on a string before feeding it to `parse` (e.g., `JSON.parse(JSON.minify("/* Hello */ 123"))`).
JSON.stringify(Object('hi'))
The issue reporter says it should return '"hi"' but returns '{"0":"h","1":"i"}'In my JS console, if I do
Object('hi')
It returns { '0': 'h', '1': 'i' }So to me, it looks like JSON2 correctly serializes the result of Object('hi'). Am I missing something?
If you're recent modern browser `JSON.stringify(Object('hi'))` should produce '"hi"'.
JSON.stringify(Object('hi'))
does that, but just plain Object('hi') without wrapping in stringify returns { '0': 'h', '1': 'i' }
Is it part of the JSON spec that you first call .toString() on array-like objects?The stringify behavior is spec'ed here http://es5.github.com/#x15.12.3 [Step 4b of the abstract operation Str(key, holder) algorithm].
Unrelated: their readme reveals a bug in github’s markdown implementation. The bold is not properly applied in the following example:
- **`String.prototype` Methods**: `indexOf`, `charAt`, `slice`.As much as I agree that the naming convention isn't great, it's better to have consistency -- especially in a language as dynamic as JavaScript.
damn you u+2028