timo / json_fast

a naive imperative json parser in perl6, to evaluate performance against JSON::Tiny
Artistic License 2.0
27 stars 20 forks source link

In README show how to get "to-json" keys sorted like "%h.keys.sort({.Numeric)" #90

Open tbrowder opened 1 year ago

tbrowder commented 1 year ago

This works (as suggested by [Coke]): define a sub suitable for the key types expected:

sub my-sort($a, $b) { $a.key cmp $b.key }
my $jstr = to-json %h, :pretty, :sorted-keys(&my-sort);

If multiple key types are expected, then the sub should use elsif or when to define what the user wants when a key pair is not directly comparable. For example, I used this sub for mixed Str and Int types:

TO BE COMPLETE A BIT LATER (when I get back to a real computer)