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

981Re: [json] Sorting the keys of formatted (pretty printed) JSON output

Expand Messages
  • Tatu Saloranta
    Apr 10, 2008
    • 0 Attachment
      On Thu, Apr 10, 2008 at 5:13 AM, Arthur Blake <arthur.blake@...> wrote:
      > On Thu, Apr 10, 2008 at 12:29 AM, Tatu Saloranta <tsaloranta@...>
      > wrote:
      > >
      > > One question: wouldn't it be easier to just use TreeMap for storing
      > > fields, instead of HashMap, if sorting is desired?
      > >
      > > -+ Tatu +-
      > That was my first thought when thinking about how to do it, as well.
      > That would make sense if you wanted to always keep and use the JSON
      > sorted. In one of my main use cases (JSON-RPC debug output on the
      > There would be a penalty for keeping a TreeMap versus a HashMap.
      > HashMap obviously performs better (constant time put & get) for when

      I understand this, and it's a valid point. But I was thinking more
      along the lines of deferring initialization of the Map, and switching
      between the two if/as necessary. That is, it'd be a property of Json
      object, to minimize sorting overhead for cases where it's not needed.

      At any rate, I just wanted to mention it as an option, just to make
      sure it was considered. And that seems to have been the case.

      -+ Tatu +-
    • Show all 7 messages in this topic