In short, according to RFC4627 a JSON-string must start with an array (i.e. [...] ) or hash (i.e. {...} ) on top level.If $enable is true (or missing), then the encode method can convert a non-reference into its corresponding string, number or null JSON value, which is an extension to RFC4627. likewise, decode will accept those JSON values instead of croaking.$json = $json->allow_nonref ([$enable]) $enabled = $json->get_allow_nonrefIf $enable is false, then the encode method will croak if it isn't passed an arrayref or hashref, as JSON texts must either be an object or array . Likewise, decode will croak if given something that is not a JSON object or array.
Example, encode a Perl scalar as JSON value with enabled allow_nonref, resulting in an invalid JSON text:
JSON::XS->new->allow_nonref->encode ("Hello, World!") => "Hello, World!"
Since many applications accept more, you have the option allow_nonref to allow simple values and strings.
As a side note: How do I post a question effectively?
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to Re: Need same JSON response from Mojo & CGI::App (extending standard JSON)
by LanX
in thread Need same JSON response from Mojo & CGI::App
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |