Hi.

I'm reading records from PostgreSQL where one column contains a UTF-8
encoded JSON-string. As DBD::Pg is UTF-8 aware it will return strings with
the utf8-flag set (https://metacpan.org/pod/DBD::Pg#pg_enable_utf8-integer).

When decoding this string with decode_json (from Mojo::JSON), it fails with
the message 'Input is not UTF-8 encoded'.

I can work around this by encoding the string back to an octet sequence
before passing the data to Mojo::JSON. But would it make sense to let
Mojo::JSON::_decode check the utf8-flag, and only run Mojo::Util::decode if
the flag is off?


Examples:

With utf8 flag set:
$ perl -Mutf8 -Mojo -E 'my $s=q/{"likes":"öl"}/; say r($s); say r(j($s))'
"{\"likes\":\"\x{f6}l\"}"


With utf8 flag unset (off):
$ perl -Mojo -E 'my $s=q/{"likes":"öl"}/; say r($s); say r(j($s))'
"{\"likes\":\"\303\266l\"}"

{
  "likes" => "\x{f6}l"
}


-- 
Pelle

Research is what I'm doing when I don't know what I'm doing.
- Wernher von Braun

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to