NAME
Skilletor::JSON::OrderedHash - A tied hash that keeps a JavaScript object's property order
VERSION
version 0.001
SYNOPSIS
use Skilletor::JSON qw( js_ordered );
my $h = js_ordered( b => 1, a => 2, 10 => 3 );
print join ',', keys %$h; # 10,b,a
DESCRIPTION
The tie class behind every object "js_parse" in Skilletor::JSON returns and "js_ordered" in Skilletor::JSON builds. keys gives what Object.keys gives for the same object in JavaScript: array-index keys ("0" to "4294967294") first, ascending by value, then every other key in the order it was first stored. Storing an existing key keeps its place; deleting it and storing it again moves a non-index key to the end. So a value read, changed and written back keeps the key order the reference implementation would keep.
is_index_key
Skilletor::JSON::OrderedHash->is_index_key('42'); # 1
True when a key is an array index in the ECMAScript sense.
keys_in_order
(tied %$h)->keys_in_order;
The keys in property order, without iterating the tied hash.
SUPPORT
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <getty@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.