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

190Re: Strings

Expand Messages
  • George
    Jan 4, 2006
      I agree 100% with you.
      Do as I do and use Javascript Object Literals as they are specified in
      the Javascript or ECMAScript Reference.

      Anything the JS parser allows is considered valid:
      - Comments
      - Quoted/Unquoted keys
      - Numbered Keys
      - Single/Double Quotes
      - Scientific Notation
      - Unicode

      It is up to the coder to define 'best practices' not the format to
      impose or restrict them.

      Then again, it is a 'subset' of JavaScript Object Literals, lowest
      common denominator to be compatible with other languages.

      If your target are web apps, HTML and JS, just go and use the whole
      set and more.

      Crockford knows I always opposed his stubbornness ;-)


      --- In json@yahoogroups.com, Martin Cooper <mfncooper@g...> wrote:
      > On 1/3/06, Douglas Crockford <douglas@c...> wrote:
      > >
      > > JSON has a string notation which is similar to that used in the C
      > > family languages. Strings are bounded by double quote characters.
      > > Escapement is provided by the backslash. The spec specifically allows
      > > the slash to be escaped so that JSON can be delivered in HTML
      > These statements have me really wondering about what JSON is
      supposed to be.
      > The reasoning behind removing comments was that it would "more
      closely align
      > JSON with YAML and Python". Now we have double quoted strings only,
      which is
      > "similar to that used in the C family language", and so that it "can be
      > delivered in HTML documents".
      > And here was me blithely thinking JSON was supposed to be a "JavaScript
      > Object Notation". What happened to the JavaScript focus? With all due
      > respect, it's beginning to seem like JSON is supposed to be a minimalist
      > object notation that's compatible with JavaScript and as many other
      > languages as possible. Perhaps it should be renamed "MON" for
      Minimal Object
      > Notation? ;-) The "JSON" moniker is seeming less and less appropriate.
      > The single quote convention is not included in JSON because it is not
      > > needed.
      > It wasn't "needed" in JavaScript / ECMAScript either, but they still
      > included it. It's convenient because it frequently allows you to avoid
      > backslashes / escapes in string literals.
      > All strings can be represented with the double quote notation.
      > > C itself does not have single quote strings. Many PHP programmers are
      > > confused by JavaScript's single quote strings.
      > Add PHP to the list of non-JavaScript languages JSON is trying to cater
      > to... (... and add PHP programmers to my list of not-so-smart-folks
      if they
      > can't understand string quoting... ;)
      > JSON requires that keys be quoted because of an error in the
      > > ECMAScript spec that disallows the use of unquoted reserved words as
      > > keys. The list of reserved words is surprisingly long and difficult to
      > > remember. The best practice is to always quote keys.
      > That is a good reason to document a "best practice". It is in no way a
      > reason to ban people from using unquoted key names.
      > As an historical note, the very first JSON message contained as one of
      > > its keys the word "do". It was not quoted, and it caused a syntax
      > Not a good start, huh? ;-)
      > --
      > Martin Cooper
      > Yahoo! Groups Links
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > [Non-text portions of this message have been removed]
    • Show all 12 messages in this topic