check json output before decoding
This should fix #332.
Merge pull request #333 from chrox/master

check json output before decoding