Handle errors from put requests correctly

Also json_encode put value when passed as a table