misterperl has asked for the wisdom of the Perl Monks concerning the following question:
$_ = encode_json $hashref
and
(DBI query) insert into table ( $id, '$_' );
I getInvalid JSON text: "Invalid encoding in string." at postition 3464 ..
I then didsplit //
and that position was the first instance of a \n. It looked like:
so evidently it split \n into 2 chars, \ and n. I'm not sure how to direct the utf conversion to treat \(letter) as a character but I think that's where the JSON string goes south?3463 '.' 3464 '\\' 3465 'n' . .
I chatGPT'ed issue and most suggestions were to replace all '\' with '\\' , so I tried some replacements like: s.([^\\])\\([^\\]).$1\\\\$2.g which had no joy: same error, same position. I'm wondering would like a cast $_ as json or json_object($_) or some other trick like that help?
AS always kind advice is greatly appreciated, and blessed Friday to all
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: JSON::XS utf8 formatted string will not load into MYSQL json type column
by Corion (Patriarch) on Aug 25, 2023 at 17:49 UTC | |
by misterperl (Friar) on Aug 25, 2023 at 19:22 UTC | |
by misterperl (Friar) on Aug 25, 2023 at 19:13 UTC | |
|
Re: JSON::XS utf8 formatted string will not load into MYSQL json type column
by misterperl (Friar) on Aug 25, 2023 at 18:28 UTC | |
by Corion (Patriarch) on Aug 25, 2023 at 18:36 UTC | |
by misterperl (Friar) on Aug 25, 2023 at 19:14 UTC |