diff --git a/crates/nu-json/src/util.rs b/crates/nu-json/src/util.rs index 5f650b1095..0d31e06a58 100644 --- a/crates/nu-json/src/util.rs +++ b/crates/nu-json/src/util.rs @@ -207,18 +207,19 @@ impl> ParseNumber { } } - if is_float { - Ok(Number::F64( - res.parse::().expect("Internal error: json parsing"), - )) - } else if res.starts_with('-') { - Ok(Number::I64( - res.parse::().expect("Internal error: json parsing"), - )) - } else { - Ok(Number::U64( - res.parse::().expect("Internal error: json parsing"), - )) + if !is_float { + if res.starts_with('-') { + if let Ok(n) = res.parse::() { + return Ok(Number::I64(n)); + } + } else if let Ok(n) = res.parse::() { + return Ok(Number::U64(n)); + } + } + + match res.parse::() { + Ok(n) => Ok(Number::F64(n)), + _ => Err(Error::Syntax(ErrorCode::InvalidNumber, 0, 0)), } } _ => Err(Error::Syntax(ErrorCode::InvalidNumber, 0, 0)),