When converting an array to json and then back again, I need to use |
or () in order to get back the original array in a @variable.
This surprised me, especially as for hashes the roundtrip worked
without any extra work.
I was wondering if this is really the expected behaviour?
Gabor
use v6;
use JSON::Fast;
#use JSON::Tiny;
my @elems1;
@elems1.push: {
name => 'Foo',
id => 1,
};
say @elems1.gist; # [{id => 1, name => Foo}]
my $json_str = to-json @elems1;
#say $json_str;
my (@elems2) = from-json $json_str;
say @elems2.gist; # [{id => 1, name => Foo}]
my @elems3 = | from-json $json_str;
say @elems3.gist; # [{id => 1, name => Foo}]
my @elems4 = from-json $json_str;
say @elems4.gist; # [[{id => 1, name => Foo}]]