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

Function json_to_value

nodedb-client/src/remote_parse.rs:68–87  ·  view source on GitHub ↗

Convert `serde_json::Value` to `nodedb_types::Value`.

(v: &serde_json::Value)

Source from the content-addressed store, hash-verified

66
67/// Convert `serde_json::Value` to `nodedb_types::Value`.
68pub(crate) fn json_to_value(v: &serde_json::Value) -> Value {
69 match v {
70 serde_json::Value::Null => Value::Null,
71 serde_json::Value::Bool(b) => Value::Bool(*b),
72 serde_json::Value::Number(n) => {
73 if let Some(i) = n.as_i64() {
74 Value::Integer(i)
75 } else {
76 Value::Float(n.as_f64().unwrap_or(0.0))
77 }
78 }
79 serde_json::Value::String(s) => Value::String(s.clone()),
80 serde_json::Value::Array(a) => Value::Array(a.iter().map(json_to_value).collect()),
81 serde_json::Value::Object(m) => Value::Object(
82 m.iter()
83 .map(|(k, v)| (k.clone(), json_to_value(v)))
84 .collect(),
85 ),
86 }
87}
88
89/// Format an f32 slice as a SQL ARRAY literal: `ARRAY[0.1,0.2,0.3]`.
90pub(crate) fn format_vector_array(v: &[f32]) -> String {

Callers 4

pg_value_to_valueFunction · 0.70
json_to_value_nestedFunction · 0.70
document_get_implMethod · 0.50
document_get_implMethod · 0.50

Calls 5

collectMethod · 0.80
as_i64Method · 0.45
as_f64Method · 0.45
cloneMethod · 0.45
iterMethod · 0.45

Tested by 1

json_to_value_nestedFunction · 0.56