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

enum values get to-json'd as their name, giving invalid json #31

Closed timo closed 6 years ago

timo commented 7 years ago
perl6 -e 'use JSON::Tiny; enum Blop <Moo Meep Squee>; say to-json([Moo, Meep, Squee]);'
[ Moo, Meep, Squee ]

Should instead be

[ "Moo", "Meep", "Squee" ]
timo commented 7 years ago

turns out i had some strange system state that gave me outdated code. what's up on cpan and github's current master will give the Int values of the enums, but i'd prefer the names as quoted strings instead. not entirely sure how my users feel about it, though.

gfldex commented 6 years ago

Enum values are not just strings, they are real objects. One could look at the value at runtime given the type information is not lost. That could be done by providing a json object.

["Blop":"Moo", "Blop":"Meep", "Blop":"Squee"]

That looks right(er) to me.

timo commented 6 years ago

no, that wouldn't work for cases like [ True, True, True ], because that'd end up as { True: True, True: True, True: True } or rather { "True": "True", "True": "True", "True": "True } which are either nonsensical or invalid.

JJ commented 5 years ago

This error just came back in the last release