MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / value_to_json

Function value_to_json

sdk-rust/src/result.rs:238–251  ·  view source on GitHub ↗

Convert a GraphLite Value to a serde_json Value

(value: &Value)

Source from the content-addressed store, hash-verified

236
237/// Convert a GraphLite Value to a serde_json Value
238fn value_to_json(value: &Value) -> serde_json::Value {
239 match value {
240 Value::Null => serde_json::Value::Null,
241 Value::Boolean(b) => serde_json::Value::Bool(*b),
242 Value::Number(n) => serde_json::json!(n),
243 Value::String(s) => serde_json::Value::String(s.clone()),
244 Value::Array(arr) | Value::List(arr) => {
245 let items: Vec<serde_json::Value> = arr.iter().map(value_to_json).collect();
246 serde_json::Value::Array(items)
247 }
248 // For complex types like Node, Edge, Path, etc., use serde serialization
249 _ => serde_json::to_value(value).unwrap_or(serde_json::Value::Null),
250 }
251}
252
253#[cfg(test)]
254mod tests {

Callers 2

value_to_typeFunction · 0.85
test_value_conversionFunction · 0.85

Calls 2

cloneMethod · 0.80
iterMethod · 0.45

Tested by 1

test_value_conversionFunction · 0.68