better JSON error handling