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

Re: [json] RSON 0.06 released

Expand Messages
  • Patrick Maupin
    ... First of all, for sequences (JSON arrays; Python lists), the order is preserved. For hashes (JSON objects), by default Python dicts are used, which does
    Message 1 of 4 , Mar 21, 2010
    • 0 Attachment
      On Sun, Mar 21, 2010 at 1:43 PM, Michael Schøler <michael@...> wrote:
      > Hi Patrick,
      >
      >
      >
      > Is the ordering of the data elements irrelevant in RSON to JSON, or is the
      > manual in error? For example, business logic could (in some cases) depend on
      > the sequence/ordering of two data elements.
      >
      >
      >
      > This may be a bit on the edge but consider for example:
      >
      >
      >
      > Action:
      >
      >                             Allocate: ScreenBuffer
      >
      >                             Draw: [10, 3, 203, 6]
      >
      >                             Deallocate: ScreenBuffer
      >
      >
      >
      > Or maybe more to the point:
      >
      >
      >
      > Transaction:
      >
      >                             Ensure: 1000.0
      >
      >                             Withdraw: 1000.0
      >
      >
      >
      > In your examples in the manual, the ordering of the resulting JSON is not
      > compliant with the ordering of the RSON data, e.g.:
      >
      >
      >
      > George: …
      >
      > Sam: …
      >
      > Morrie: …
      >
      >
      >
      > becomes:
      >
      >
      >
      > {
      >
      >  “Morrie”: …
      >
      >  “George”: …
      >
      >  “Sam” …
      >
      > }
      >

      First of all, for sequences (JSON arrays; Python lists), the order is
      preserved. For hashes (JSON objects), by default Python dicts are
      used, which does not preserve the order. As with the Python json or
      simplejson decoders (which also use dicts by default and thus also do
      not preserve order), you can specify a function that receives the
      ordered pairs of key/values (or if you wish to use the enhanced syntax
      which allows nested keys, you can specify a function that receives
      tuples of (key, [key, ...] value])).

      So, by default, the order of key/value pairs in objects is not
      preserved. (Is it in JavaScript?) But you can override that default
      behavior if you wish to do so.

      Best regards,
      Pat
    • Michael Schøler
      ... Hi, Fair enough. No it isn t in JavaScript regarding object properties (or JSON for that matter). Only with regards to serialization and de-serialization
      Message 2 of 4 , Mar 21, 2010
      • 0 Attachment
        > First of all, for sequences (JSON arrays; Python lists), the order is
        > preserved. For hashes (JSON objects), by default Python dicts are
        > used, which does not preserve the order. As with the Python json or
        > simplejson decoders (which also use dicts by default and thus also do
        > not preserve order), you can specify a function that receives the
        > ordered pairs of key/values (or if you wish to use the enhanced syntax
        > which allows nested keys, you can specify a function that receives
        > tuples of (key, [key, ...] value])).
        >
        > So, by default, the order of key/value pairs in objects is not
        > preserved. (Is it in JavaScript?) But you can override that default
        > behavior if you wish to do so.
        >
        > Best regards,
        > Pat

        Hi,

        Fair enough. No it isn't in JavaScript regarding object properties (or JSON
        for that matter). Only with regards to serialization and de-serialization
        (and obviously for Array's). When you need it for some purpose on objects
        the trick is usually therefore to make an array and keep the
        ordinality/indexing info there for each desired ordered object property.

        However, you might just comment on this fact in your RSON manual (however
        clear and apparent it may be for some devs) ;-)

        Many are confused about this specific topic - and I catch it out of the
        corner of my eye nearly every time I come across it, because I have made a
        great deal of JSON to XML and back again - and in XML documents, ordinality
        matters (XPATH can use element indexes).

        Best regards,
        Michael Schøler
      Your message has been successfully submitted and would be delivered to recipients shortly.