sa624b@att.com has asked for the wisdom of the Perl Monks concerning the following question:

Can some one help me out, what exactly the fallowing message implies and what would be the solution. Thanks ... :-) malformed JSON string, neither array, object, number, string or atom, at charact er offset 0 (before "Not a SCALAR referen...") at test.pl line 109.

Replies are listed 'Best First'.
Re: improper json response
by choroba (Cardinal) on Mar 16, 2012 at 16:03 UTC
    You are trying to build a structure from a string that should be JSON, but it is not: instead, it contains a Perl error message "Not a SCALAR reference...". The source of the problem is probably the code that generates the JSON string, not the code that tries to read it.
Re: improper json response
by locked_user sundialsvc4 (Abbot) on Mar 16, 2012 at 19:23 UTC

    I ran into exactly the same problem (yes, on the server side) when I was trying to JSONify a structure which I forgot had a sub (that is, a code-reference) in it.   When my code referred to that element of the underlying structure, then I know that Perl will conveniently call the subroutine for me and hand me back the value ... which is what I intended ... but JSON-encoding routines are a bit more literal in their world-view.   I had to be very careful to prepare a data-structure for encoding purposes that contained nothing but values.   Yup, it was an easy fix once I realized what was wrong, and, yup, I had pretty much the same “WTF?!” experience as you just did.   (Followed rather immediately by, “Oh...   well, duh...”)

Re: improper json response
by remiah (Hermit) on Mar 17, 2012 at 11:12 UTC