Loading ...
Sorry, an error occurred while loading the content.

Re: json2 vs FF3 behaviour - jsonstring in array

Expand Messages
  • nostalgiker
    ... thank you, that was the answer is was looking for. should have checked the spec...
    Message 1 of 13 , Jan 7, 2010
    • 0 Attachment
      > 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...
    • nostalgiker
      is mr.crockford reading this list? imo this is then a bug in json2.js since JSON.parse([ true ]) fails in his implementation but it should behave like ecma5 s
      Message 2 of 13 , Jan 7, 2010
      • 0 Attachment
        is mr.crockford reading this list? imo this is then a bug in json2.js since JSON.parse(['true']) fails in his implementation but it should behave like ecma5's native JSON.

        greetings
        simon
      • Douglas Crockford
        ... JSON.parse wants to be called with a string. If you call it with anything else, you get what you deserve. I don t recommend reliance on the edge cases.
        Message 3 of 13 , Jan 7, 2010
        • 0 Attachment
          --- In json@yahoogroups.com, "nostalgiker" <nostalgiker@...> wrote:

          > is mr.crockford reading this list? imo this is then a bug in json2.js since JSON.parse(['true']) fails in his implementation but it should behave like ecma5's native JSON.


          JSON.parse wants to be called with a string. If you call it with anything else, you get what you deserve. I don't recommend reliance on the edge cases. That is where systems are the least portable.
        • Fredag_d13
          I 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
          Message 4 of 13 , Jan 7, 2010
          • 0 Attachment
            I 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."

            bummer.

            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.

            What you should do, is to encode your javascript-array into json before parsing it:

            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 json@yahoogroups.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...
            >
          • Fredag_d13
            Wait a minute - ignore my last advice. That would probably give you escaped characters instead of what you want. Just dont feed parsers anything but plain
            Message 5 of 13 , Jan 7, 2010
            • 0 Attachment
              Wait a minute - ignore my last advice.
              That would probably give you escaped characters instead of what you want. Just dont feed parsers anything but plain text.

              --- In json@yahoogroups.com, "Fredag_d13" <jonas@...> wrote:
              >
              >
              >
              > I 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."
              >
              > bummer.
              >
              > 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.
              >
              > What you should do, is to encode your javascript-array into json before parsing it:
              >
              > 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 json@yahoogroups.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...
              > >
              >
            • Fredag_d13
              Wait a minute - ignore my last advice. That would probably give you escaped characters instead of what you want. Just dont feed parsers anything but plain
              Message 6 of 13 , Jan 7, 2010
              • 0 Attachment
                Wait a minute - ignore my last advice.
                That would probably give you escaped characters instead of what you want. Just dont feed parsers anything but plain text.

                --- In json@yahoogroups.com, "Fredag_d13" <jonas@...> wrote:
                >
                >
                >
                > I 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."
                >
                > bummer.
                >
                > 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.
                >
                > What you should do, is to encode your javascript-array into json before parsing it:
                >
                > 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 json@yahoogroups.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...
                > >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.