in reply to JSON::XS produces valid utf-8, and JSON doesn't - why?

Some remarks:

my $ok = utf8::decode($json); is not the best way to validate utf8. Because:
  1. It only validates Perl's notion of utf-8. Which is not exactly what the Unicode Consortium says.
    use feature 'say'; binmode STDOUT, 'encoding(utf-8)'; my $str = "\xFC\x90\x80\x80\x80\x80"; my $ok = utf8::decode( $str ); say $ok ? 'ok' : 'not ok'; say $str;
    output:
    ok Code point 0x10000000 is not Unicode, may not be portable at demo.pl l +ine 8. "\x{10000000}" does not map to utf8 at demo.pl line 8. \x{10000000}
  2. It always decodes a string in place. So doing
    my $ok = utf8::decode($json); Dump( $json );
    is not super useful
Second, according to JSON's docs, encode_json is equivalent to JSON->new->utf8->encode($perl_scalar), while to_json is JSON->new->encode($perl_scalar). I don't know how these modules work, but the presence/absence of ->utf8 probably makes some difference?