mysql_value_to_json

Function mysql_value_to_json 

Source
pub fn mysql_value_to_json(value: &Value) -> Result<Value>
Expand description

Convert a MySQL Value to JSON Value

Handles all MySQL data types with lossless conversion:

  • Integers → JSON numbers
  • Floats/Doubles → JSON numbers (non-finite as strings)
  • Decimals → Strings (to preserve precision)
  • Strings → JSON strings
  • Dates/Times → ISO 8601 strings in special object
  • Binary data → Base64 encoded in special object
  • NULL → JSON null

§Arguments

  • value - MySQL Value to convert

§Returns

JSON Value representing the MySQL value

§Examples

let mysql_val = Value::Int(42);
let json_val = mysql_value_to_json(&mysql_val).unwrap();
assert_eq!(json_val, serde_json::json!(42));