in reply to Re^2: Convert \u characters into utf8
in thread Convert \u characters into utf8

No. I'm suggesting that you use a JSON module for loading JSON data. There should be no need at least with the two JSON modules I mentioned to manually convert \uXXXX to their Unicode equivalents.

use JSON; use Data::Dumper; $Data::Dumper::Useqq = 1; my $data = decode_json( $file_content ); warn Dumper $data;

Note that File::Slurp is horribly broken regarding encodings. Some comments recommend File::Slurper, but I instead roll my own, which isn't rocket surgery either.

Replies are listed 'Best First'.
Re^4: Convert \u characters into utf8
by ultranerds (Hermit) on Feb 02, 2016 at 13:34 UTC
    Ahhh beautiful! I didn't realise they did the job for you. So I have this now:

    my $as_str; open (READIT,"./in.txt"); $as_str = <READIT>; close(READIT); my $json_var = decode_json($as_str); open (OUT, ">./foo.txt") || die $!; print OUT encode_json($json_var); close (OUT);


    That seems to have done the trick :)

    Just out of interest - in NotePad++, if I look at the encoding, I see it as:

    Encode in UTF-8 without BOM

    I'm a bit confused as to how it has saved it like that, when I didn't specifically tell it to save in UTF8 format?

    Cheers

    Andy