CropCircle has asked for the wisdom of the Perl Monks concerning the following question:
Hello! I have a variable ($json), which contains some json structure, then try to write it in data_out file but get this error: malformed text data., at character offset 0 (before "HASH(0x39e290)"). Here is the code:
use strict; use warnings; binmode STDOUT, ":utf8"; use utf8; use JSON; my $json ={ 'book' => { 'title' => 'smth', 'num_page' => 234 } }; my $data = decode_json($json); open my $fh, ">", "data_out.json"; print $fh encode_json($data); close $fh;
Have no ideas how to fix it. Thanks for help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Write json structure to a file
by Corion (Patriarch) on Aug 13, 2015 at 11:29 UTC | |
by CropCircle (Novice) on Aug 13, 2015 at 12:20 UTC | |
by Corion (Patriarch) on Aug 13, 2015 at 12:22 UTC | |
by MidLifeXis (Monsignor) on Aug 13, 2015 at 13:32 UTC | |
by anonymized user 468275 (Curate) on Aug 13, 2015 at 12:34 UTC | |
by Anonymous Monk on Oct 20, 2017 at 05:26 UTC | |
by Corion (Patriarch) on Oct 20, 2017 at 08:38 UTC | |
| |
by hippo (Archbishop) on Oct 20, 2017 at 08:31 UTC | |
|