Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: json text or perl structure exceeds maximum nesting level

by Corion (Patriarch)
on Jun 01, 2018 at 07:43 UTC ( [id://1215599]=note: print w/replies, xml ) Need Help??


in reply to json text or perl structure exceeds maximum nesting level

First, your call to ->max_depth doesn't do what you think it does. I think you should call it as:

JSON::XS->new->utf8->max_depth(100);

that is, leave the square brackets out.

Second, maybe your data structure cannot be serialized as JSON because it is circular? Have you inspected your data structure using Data::Dumper to see what it looks like?

#!perl -w use strict; use JSON::XS; # Create a simple circular data structure: my $output; $output = ['foo']; $output->[1] = $output; my $json = JSON::XS->new->utf8->max_depth(100); use Data::Dumper; print Dumper $output; print $json->encode($output); __END__ json text or perl structure exceeds maximum nesting level (max_depth s +et too low?) at tmp.pl line 13.

Replies are listed 'Best First'.
Re^2: json text or perl structure exceeds maximum nesting level
by Anonymous Monk on Jun 01, 2018 at 15:55 UTC
    If I was a gambler, I would say that a circular structure is almost certain to be the problem here.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-26 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found