check json output before decoding
This should fix #332.