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

Re: [json] Order of members and equality

Expand Messages
  • Jonathan Wallace
    Interesting, internally they use a custom container, but has named access time of O(n) so unordered comparison would end up being arithmetic sum of n. I
    Message 1 of 5 , Oct 10, 2012
    • 0 Attachment
      Interesting, internally they use a custom container, but has named access time of O(n) so unordered comparison would end up being arithmetic sum of n. I figured in JavaScript it wouldn't matter, but there are lots of people in other languages that use Json in other ways. If the rfc is silent on it, then it would be library specific and not to be relied on. Perhaps I will add a seperate function for this.

      Sent from my iPhone

      On Oct 9, 2012, at 10:28, John Cowan <cowan@...> wrote:

      > jonathan wallace scripsit:
      >
      > > Should those two nodes be considered equal to each other? I am
      > > certain that order matters when it comes to arrays, and I am fairly
      > > certain that it is for members as well, am I wrong?
      >
      > I think you are wrong, and that order does not matter when it comes to
      > objects, though the JSON RFC is characteristically silent on the point.
      > JSON objects are basically JavaScript objects, and it's clear that in
      > JavaScript there is no ordering information available, so anyone who
      > depended on the order of members wouldn't be able to recover it.
      >
      > How are you representing JSON objects internally? If they are just C++
      > arrays, then the naive algorithm for order-independent equality is O(N^2),
      > which is rather larger than a C++ programmer would expect. Sorting the
      > objects at time of comparison drops the cost to O(N log N). (Still,
      > typical JSON objects may be small enough that constant factors dominate.)
      >
      > --
      > Take two turkeys, one goose, four John Cowan
      > cabbages, but no duck, and mix them http://www.ccil.org/~cowan
      > together. After one taste, you'll duck cowan@...
      > soup the rest of your life.
      > --Groucho
      >


      [Non-text portions of this message have been removed]
    • douglascrockford
      ... An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or
      Message 2 of 5 , Oct 12, 2012
      • 0 Attachment
        --- In json@yahoogroups.com, John Cowan <cowan@...> wrote:

        > I think you are wrong, and that order does not matter when it comes to
        > objects, though the JSON RFC is characteristically silent on the point.


        An object is an unordered collection of zero or more name/value
        pairs, where a name is a string and a value is a string, number,
        boolean, null, object, or array.


        http://www.ietf.org/rfc/rfc4627.txt?number=4627
      • John Cowan
        ... Touche. And thanks. -- [W]hen I wrote it I was more than a little John Cowan febrile with foodpoisoning from an antique carrot
        Message 3 of 5 , Oct 12, 2012
        • 0 Attachment
          douglascrockford scripsit:

          > > I think you are wrong, and that order does not matter when it comes to
          > > objects, though the JSON RFC is characteristically silent on the point.
          >
          > An object is an unordered collection of zero or more name/value
          > pairs, where a name is a string and a value is a string, number,
          > boolean, null, object, or array.

          Touche. And thanks.

          --
          [W]hen I wrote it I was more than a little John Cowan
          febrile with foodpoisoning from an antique carrot cowan@...
          that I foolishly ate out of an illjudged faith http://ccil.org/~cowan
          in the benignancy of vegetables. --And Rosta
        Your message has been successfully submitted and would be delivered to recipients shortly.