in reply to improper json response

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...”)