Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: JSON::XS Wide Character Problem

by 1nickt (Canon)
on Jun 04, 2022 at 11:14 UTC ( [id://11144388]=note: print w/replies, xml ) Need Help??


in reply to JSON::XS Wide Character Problem

Hi, JSON::XS does UTF8 decoding by default when you use the functional interface (see the documentation), so you don't need the encoding layer on your open call.

In this example I am allowing JSON::XS to decode from UTF8, and then encoding back to UTF8 when I want to print part of the data.

use strict; use warnings; use JSON::XS; use Path::Tiny; use Encode 'encode_utf8'; my $path = '~/monks/json.txt'; my $json = path($path)->slurp; my $data = decode_json($json); my $text = encode_utf8($data->{text}); print $text, "\n"; __END__

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: JSON::XS Wide Character Problem
by cormanaz (Deacon) on Jun 04, 2022 at 22:24 UTC
    That did it, and it also solved the problem of processing a large file full of those objects (see reply above).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144388]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found