in reply to Re: how to get Perl hash in C#
in thread how to get Perl hash in C#

OK,

When I try to run this:

my $JSON = JSON->new->utf8; $JSON->convert_blessed(1); $JSON->allow_blessed(1); $JSON->pretty(1); my $json = $JSON->encode(\%arr_hash); print "JSON [\n $json\n ]\n";
I only get the root level data and the rest are null!
JSON [ { "ace_context" : [ null, null, null, null, null, null, null, null ], "server_nmap" : [ null, null, ... null ] }
Same thing happends when I try this:
my $json = $JSON->encode(\@ace_context);
BUT when I run this:

print Dumper(\%arr_hash);

the output contains everything.

How the JSON code should look like in order to "export" everything to JSON-format data?

Replies are listed 'Best First'.
Re^3: how to get Perl hash in C#
by tobyink (Canon) on Jan 24, 2014 at 14:12 UTC

    What is this "everything" that appears in the Data::Dumper output? Is it stuff that would be nonsensical in JSON output? (e.g. coderefs, pointers to open file handles, etc)

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
      Hi,

      Tha hash values are arrays. These arrays can contain some hash too. Below is the output from Data::Dumper.

      I need these values imported av hash/"collection" in C#

      $VAR1 = bless( { 'INTERFACE' => [ undef, 'vlanX' ], 'LOCATION' => 'X3', 'ACELOGICAL' => 'user', 'CHILD' => [ bless( { 'IPROUTE' => '0.0.0.0 0.0.0.0 x +xx.xxx.x.x.', 'NAME' => 'vlanX', 'ACE' => 'ACEx', 'CHILD' => [ bless( { 'IPROUTE' + => undef, 'NAME' => 'name', 'INTERFACE' => 'vlanX', 'ACE' => undef, 'SERVERFARM' => undef, 'CHILD' => [], 'OSID' => [], 'ALIAS' => undef, 'OBJECTID' => undef, 'PARENT' => [ $VAR1->{'CHILD'}[0] ], 'MASTERSHAPE' => 'ACE_RSERVER', 'CONTEXT' => 'Cntext', 'SHAPEID' => [], 'IPADDRESS' => 'xxx.xxx.x.xx' }, 'some value' ), 'IPROUTE' + => undef, 'NAME' => 'name', 'INTERFACE' => 'vlanX', 'ACE' => undef, 'SERVERFARM' => undef, 'CHILD' => [], 'OSID' => [], 'ALIAS' => undef, 'OBJECTID' => undef, 'PARENT' => [ $VAR1->{'CHILD'}[0] ], 'MASTERSHAPE' => 'ACE', 'CONTEXT' => 'some value ', 'SHAPEID' => [], 'IPADDRESS' => 'xxx.xxx.x.xx' }, 'some value' ), . . .

        JSON cannot transport "objects". What would C# do with Perl classes?

        You will need to convert your objects to plain hashes (or arrays) that contain the relevant data.