Check if a JSON value is truthy (for boolean contexts). - `true` → true, `false` → false - `null` → false - Numbers: non-zero → true - Strings: non-empty → true - Arrays/Objects: always true
(v: &serde_json::Value)
| 72 | /// - Strings: non-empty → true |
| 73 | /// - Arrays/Objects: always true |
| 74 | pub fn is_truthy(v: &serde_json::Value) -> bool { |
| 75 | match v { |
| 76 | serde_json::Value::Bool(b) => *b, |
| 77 | serde_json::Value::Null => false, |
| 78 | serde_json::Value::Number(n) => n.as_f64().unwrap_or(0.0) != 0.0, |
| 79 | serde_json::Value::String(s) => !s.is_empty(), |
| 80 | _ => true, |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /// Convert a JSON value to a display string. |
| 85 | /// |
no test coverage detected