Throw appropriate error with invalid JSON