Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1252 (closed enhancement: fixed)

Opened 16 years ago

Last modified 14 years ago

Rountrip parse/print of JSON changes order of object attributes

Reported by: BenjiSmith Assigned to: kris
Priority: minor Milestone: 0.99.9
Component: Core Functionality Version: trunk
Keywords: Cc:

Description

NOTE: I recognize that this is a slightly frivolous enhancement request :-)

Parsing a JSON string and then invoking the "print" delegate results in a different (though equivalent) JSON string, since the object key/value pairs are written in a different order than they occurred in the original string.

  auto v1 = p.parse (`{"t": true, "n":null, "array":["world", [4, 5]]}`);
  v1.print((char[] s) {Stdout(s);});

...prints...

{"array":["world", [4.00, 5.00]],"n":null,"t":true}

In my own JSON implementation (in Java), I've used a LinkedHashMap? to keep the nodes in their original declaration order. I was thinking that "tango.util.collection.LinkMap?" might make a nice replacement, but then I remembered that the "collection" API is deprecated in favor of the "container" API, and the containers don't have a linked-map implementation.

Anyhow, like I said, it's a low-priority enhancement request. For some large JSON documents, maintaining the declaration order can make debugging a little easier, but that's probably the only real benefit.

Change History

08/17/08 03:13:43 changed by kris

  • status changed from new to assigned.

yeah, the implementation is deliberately cheap this way for the sake of throughput. I'll see about reversing at print-time instead. Thanks for the report

10/05/08 04:06:04 changed by kris

  • milestone changed from 0.99.8 to 0.99.9.

11/09/09 05:26:27 changed by kris

  • status changed from assigned to closed.
  • resolution set to fixed.

this was fixed ages ago :)