MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / is_truthy

Function is_truthy

nodedb-query/src/json_ops.rs:74–82  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

72/// - Strings: non-empty → true
73/// - Arrays/Objects: always true
74pub 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///

Callers 6

eval_castFunction · 0.70
eval_scopeMethod · 0.50
eval_binary_opFunction · 0.50
matches_valueMethod · 0.50
matches_binaryMethod · 0.50

Calls 2

as_f64Method · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected