in reply to Maintainance of element order in hash

Are you absolutely committed to relying on JSON objects preserving order? If your design mandates that to be the case, you would be better off making your filtered element contain an array of objects rather than object elements. This is a problem that my be solved by one level of indirection.

If there is any possibility that you can annul your marriage to a design that requires ordered JSON objects, I think you should give that possibility due consideration.

Here are a few reasons why:

Perl's hashes have a high degree of parity with JSON objects. Standard Perl hashes do not maintain any concept of static order. You can tie a Perl hash to a class that maintains order, but in doing so you make tradeoffs, giving away speed and memory for reliable ordering. Is it worth the tradeoff? If so, you may need to also rethink the serialization format you are using, because JSON isn't guaranteed to serialize and deserialize objects in any particular order. Any guarantees would have to come from the implementation. As an example, JSON parsers such as JSON::XS allow you to specify canonical ordering for object keys. But canonical is used to mean a sorted order. Not a user-specified order.


Dave