1439Re: json2 vs FF3 behaviour - jsonstring in array
- Jan 7, 2010I believe that the EMCAScript standard should be changed.
On page 212 in http://www.ecmascript.org/docs/tc39-2009-043.pdf
ECMA specifies the JSON-grammar, but does not do so by the specification given by Crockford. http://tools.ietf.org/html/rfc4627
He specifies (page 2) that:
"A JSON text is a serialized object or array.
JSON-text = object / array"
ECMA says that JSONText is JSONValue, which is too liberal as it would also mean that JSONString, JSONNumber, etc. is JSONText.
Doing it the ECMA standard way would (as previously said) convert ["text"] it into 'text' or '"text"' - which isen't JSONText, but that what the ECMAstandard tells you to do.
The Native parser is actually a valid JSON parser. The spec says so:
"A JSON parser MUST accept all texts that conform to the JSON grammar. A JSON parser MAY accept non-JSON forms or extensions."
But it would be interesting to see if JSON.stringify is outputting JSONText according to the spec given by D.Crockford or the self-invented JSON grammar by ECMA.
Anyway - It's always sane to feed a parser text, because a parser works on text (http://en.wikipedia.org/wiki/Parsing) - that's why json2.js should not be changed and ECMAScript 5 should be modified.
var a = ["text"];
var json_a = JSON.stringify(a); //gives you '["text"]'
var a_array = JSON.parse(json_a);
(I haven't tested this code - might not be bug free)
--- In email@example.com, "nostalgiker" <nostalgiker@...> wrote:
> > Neither are correct.
> > The ECMAScript 5 spec states the first step of JSON.parse is
> > to call ToString( text ).
> thank you, that was the answer is was looking for. should have checked the spec...
- << Previous post in topic Next post in topic >>