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

Cannot to-json(Seq) etc #3

Closed skaji closed 9 years ago

skaji commented 9 years ago

In #2, to-json function changed drastically.

In https://github.com/timo/json_fast/blob/master/lib/JSON/Fast.pm#L19, to-json checks whether $obj is array-like or not by ~~ Array. Then Seq, List, ... is not array-like and to-json(Seq) does not work.

> perl6 -MJSON::Fast -e 'my $a = gather for 1..5 { take $_ }; $a.WHAT.say; to-json $a'
(Seq)
# HANG UP!
# actually throws exception many times: Type Seq does not support associative indexing.

I think we should check whether $obj is array-like or not by multi to-json(Positional:D $obj) as before.

timo commented 9 years ago

498135a8df3986e80e1c552145aad6f39ecb19a0 addresses this; is it good enough?

skaji commented 9 years ago

@timo Thanks, you're fast! Yes, it works. I close this issue.

PS. This is not a related issue, but maybe should we care about 'null'?

> perl6 -MJSON::Fast -e 'my $a; to-json($a).say'
{

}
> perl6 -e 'my $a; to-json($a).say'
null