Convert a GraphLite Value to a serde_json Value
(value: &Value)
| 236 | |
| 237 | /// Convert a GraphLite Value to a serde_json Value |
| 238 | fn 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)] |
| 254 | mod tests { |