Perl-Sensitive Sunglasses | |
PerlMonks |
Rogue character(s) at start of JSON fileby Bod (Parson) |
on Jan 16, 2023 at 22:01 UTC ( [id://11149618]=perlquestion: print w/replies, xml ) | Need Help?? |
Bod has asked for the wisdom of the Perl Monks concerning the following question: I'm processing some JSON files using JSON and getting this error: So I printed out the JSON file from the Perl script and sure enough there are three rogue characters before the opening square bracket. These do not show up in my text editor TextPad. A search has found this explanation. However, the JSON files are being pulled from a UK Government data source and I have no control over how they are made. So I have to deal with the character(s) somehow. Here's my test code:
Unpacking the first three characters gives 239 - 187 - 191 and the substitution seems to have the desired effect but it seems to be a bit of a fudge! Can you suggest a "better" way to deal with this? The output from Data::Dumper is a bit strange: I've come across bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ) before instead of false but not $VAR1->[0]{'test'}. I guess this is so Data::Dumper doesn't have to create an object for each boolean. It instead it represents them in terms of ones it has previously created. Is that about right? I have proved that this is just Data::Dumper and not the underlying data structure by this dereference: Which produces zeros and ones for false and true...
Back to
Seekers of Perl Wisdom
|
|