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

Function compare_json

nodedb/src/bridge/json_ops.rs:29–38  ·  view source on GitHub ↗

Compare two JSON values with type coercion. Tries numeric comparison first (with bool coercion), then falls back to string comparison.

(a: &serde_json::Value, b: &serde_json::Value)

Source from the content-addressed store, hash-verified

27/// Tries numeric comparison first (with bool coercion), then falls
28/// back to string comparison.
29pub fn compare_json(a: &serde_json::Value, b: &serde_json::Value) -> Ordering {
30 // Try numeric comparison with bool coercion.
31 if let (Some(na), Some(nb)) = (json_to_f64(a, true), json_to_f64(b, true)) {
32 return na.partial_cmp(&nb).unwrap_or(Ordering::Equal);
33 }
34 // Fallback: string comparison.
35 let sa = json_to_display_string(a);
36 let sb = json_to_display_string(b);
37 sa.cmp(&sb)
38}
39
40/// Compare two optional JSON values (for scan_filter compatibility).
41pub fn compare_json_optional(

Callers 1

compare_json_optionalFunction · 0.70

Calls 4

json_to_f64Function · 0.70
json_to_display_stringFunction · 0.70
partial_cmpMethod · 0.45
cmpMethod · 0.45

Tested by

no test coverage detected