Repository: tursodatabase/limbo (language: rust)

Issue:
floating point numbers get truncated in json
Running `SELECT json_object('a', 40.7128)` in sqlite3 yields `{"a":40.7128}` but in limbo it yields `{"a":40.7}`. Same with `json_array` or any other json function, but if you run `SELECT 40.7128` both sqlite3 and limbo yields the correct `40.7128`;


Discussion / hints:

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 6a6c9f418..132bfdee9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1645,6 +1645,7 @@ dependencies = [
  "rstest",
  "rusqlite",
  "rustix",
+ "ryu",
  "serde",
  "sqlite3-parser",
  "strum",
@@ -2680,9 +2681,9 @@ dependencies = [
 
 [[package]]
 name = "ryu"
-version = "1.0.18"
+version = "1.0.19"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
+checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd"
 
 [[package]]
 name = "same-file"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 0f5b77780..3e6a3009b 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -72,6 +72,7 @@ strum = "0.26"
 parking_lot = "0.12.3"
 tracing = "0.1.41"
 crossbeam-skiplist = "0.1.3"
+ryu = "1.0.19"
 
 [build-dependencies]
 chrono = "0.4.38"
diff --git a/core/json/ser.rs b/core/json/ser.rs
index 680296c55..ee0f1b13d 100644
--- a/core/json/ser.rs
+++ b/core/json/ser.rs
@@ -785,13 +785,8 @@ pub trait Formatter {
                 writer.write_all(infinity.as_bytes())?;
             }
             _ => {
-                // let mut buffer = ryu::Buffer::new();
-                // let s = buffer.format_finite(value);
-
-                // This the previous implementation present in the package
-                // However, serde_json does it differently above.
-                // Not sure if there if its done like this because of the precision
-                let s = &format!("{:.1}", value);
+                let mut buffer = ryu::Buffer::new();
+                let s = buffer.format_finite(value);
                 writer.write_all(s.as_bytes())?;
             }
         }


Test patch:
diff --git a/testing/json.test b/testing/json.test
index 7a1890369..d5fa827d9 100755
--- a/testing/json.test
+++ b/testing/json.test
@@ -637,6 +637,10 @@ do_execsql_test json_object_simple {
   SELECT json_object('key', 'value');
 } {{{"key":"value"}}}
 
+do_execsql_test json_object_f64 {
+  SELECT json_object('key', 40.7128);
+} {{{"key":40.7128}}}
+
 do_execsql_test json_object_nested {
   SELECT json_object('grandparent',json_object('parent', json_object('child', 'value')));
 } {{{"grandparent":{"parent":{"child":"value"}}}}}