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

Re: [json] parseJSON

Expand Messages
  • Peter Michaux
    ... Would this general purpose filter as a property of Object.prototype be instead of or in addition to the argument to parseJSON? Could filter take a second
    Message 1 of 7 , Jan 10, 2007
    • 0 Attachment
      On 1/10/07, Douglas Crockford <douglas@...> wrote:
      > The parseJSON method currently takes a filter function parameter. It
      > will be invoked for every name/value in the structure.
      > myData = text.parseJSON(function (key, value) { return
      > key.indexOf('date') >= 0 ? new Date(value) : value; });
      > The filtration mechanism is just a general purpose map function. It
      > could be exposed as a separate method and used independently. If we were
      > to do that, then it could be used like this:
      > myData = text.parseJSON().filter(function (key, value) { return
      > key.indexOf('date') >= 0 ? new Date(value) : value; });
      > Do you think a general purpose .filter method is useful? Should it be
      > added to ECMAScript?

      Would this general purpose filter as a property of Object.prototype be
      instead of or in addition to the argument to parseJSON?

      Could filter take a second parameter to specify if it is "deep" filter
      or not? That is, whether or not it will descend through the structure
      or only operate on the top level.

      It looks like the general purpose version is not harder to use and
      could be useful in many situations (i did something just like it
      recently to clean up empty nodes in a structure). It has the feel of
      Enumerable.each() in the Prototype library. If this filter is added to
      JavaScript perhaps some of the other Ruby enumerable, array and hash
      functions could be considered for addition.

      Peter
    • Peter Michaux
      ... Calling it filter may cause a namespace problem? Peter
      Message 2 of 7 , Jan 10, 2007
      • 0 Attachment
        On 1/10/07, Douglas Crockford <douglas@...> wrote:
        >
        > The parseJSON method currently takes a filter function parameter. It
        > will be invoked for every name/value in the structure.
        > myData = text.parseJSON(function (key, value) { return
        > key.indexOf('date') >= 0 ? new Date(value) : value; });
        > The filtration mechanism is just a general purpose map function. It
        > could be exposed as a separate method and used independently. If we were
        > to do that, then it could be used like this:
        > myData = text.parseJSON().filter(function (key, value) { return
        > key.indexOf('date') >= 0 ? new Date(value) : value; });
        > Do you think a general purpose .filter method is useful? Should it be
        > added to ECMAScript?


        Calling it "filter" may cause a namespace problem?

        <URL: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:filter>

        Peter
      • Michael Schwarz
        It looks like the LINQ features in C# 3.0: http://tirania.org/blog/archive/2007/Jan-10.html ;) ... -- Best regards | Schöne Grüße Michael Microsoft MVP -
        Message 3 of 7 , Jan 11, 2007
        • 0 Attachment
          It looks like the LINQ features in C# 3.0:
          http://tirania.org/blog/archive/2007/Jan-10.html

          ;)




          On 1/10/07, Douglas Crockford <douglas@...> wrote:
          >
          >
          >
          >
          >
          >
          >
          > The parseJSON method currently takes a filter function parameter. It
          > will be invoked for every name/value in the structure.
          > myData = text.parseJSON(function (key, value) { return
          > key.indexOf('date') >= 0 ? new Date(value) : value; });
          > The filtration mechanism is just a general purpose map function. It
          > could be exposed as a separate method and used independently. If we were
          > to do that, then it could be used like this:
          > myData = text.parseJSON().filter(function (key, value) { return
          > key.indexOf('date') >= 0 ? new Date(value) : value; });
          > Do you think a general purpose .filter method is useful? Should it be
          > added to ECMAScript?
          >
          > [Non-text portions of this message have been removed]
          >
          >



          --
          Best regards | Schöne Grüße
          Michael

          Microsoft MVP - Most Valuable Professional
          Microsoft MCAD - Certified Application Developer

          http://weblogs.asp.net/mschwarz/
          http://www.ajaxpro.info/

          WPF/E: http://groups.google.com/group/wpf-everywhere

          Skype: callto:schwarz-interactive
          MSN IM: passport@...
        • Douglas Crockford
          Safari s regular expression engine performs horribly on regular expressions on large texts. Tobie Langel suggested a workaround for parseJSON by splitting the
          Message 4 of 7 , Jun 20, 2007
          • 0 Attachment
            Safari's regular expression engine performs horribly on regular
            expressions on large texts. Tobie Langel suggested a workaround for
            parseJSON by splitting the regular expression in three with no loss of
            security.

            http://json.org/json.js
          Your message has been successfully submitted and would be delivered to recipients shortly.