Coerce a JSON value to f64. - Numbers: `as_f64()` directly - Strings: parse as f64 (`"5"` → `5.0`) - Booleans: `true` → `1.0`, `false` → `0.0` (when `coerce_bool` is true) - Other types: `None`
(v: &serde_json::Value, coerce_bool: bool)
| 14 | /// - Booleans: `true` → `1.0`, `false` → `0.0` (when `coerce_bool` is true) |
| 15 | /// - Other types: `None` |
| 16 | pub fn json_to_f64(v: &serde_json::Value, coerce_bool: bool) -> Option<f64> { |
| 17 | match v { |
| 18 | serde_json::Value::Number(n) => n.as_f64(), |
| 19 | serde_json::Value::String(s) => s.parse::<f64>().ok(), |
| 20 | serde_json::Value::Bool(b) if coerce_bool => Some(if *b { 1.0 } else { 0.0 }), |
| 21 | _ => None, |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | /// Compare two JSON values with type coercion. |
| 26 | /// |
no test coverage detected